Bash script to back up Opera files.

Forums » Opera for Windows/Mac/Linux » Opera for *nix - Linux/FreeBSD

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

18. October 2006, 14:54:04

Tracio

Posts: 4108

Bash script to back up Opera files.

I use this script to back up the Opera profile directory so if someone wants to use it, here it goes...

I wrote it so it could be run as a cron job (set to run it every week) thus the script does not have a GUI nor it checks for command line arguments. Of course, you can run it everytime you want (manually or via cron) once you give it execute permission.

Here's what the script does:

  • Backs up the opera profile directory of the user who runs the script (it assumes the path is ~/.opera) excluding the cache and images folders and ***including the mail directory***. The mail directory can be excluded uncomenting the variable and adding an exception to 'tar'.
  • By default it creates a tarball (tar.bz2) and a log file every time the script is run. However an option to use RAR instead of tar is provided too.
    RAR INFO:
    The RAR command will encrypt the archive (both file data and headers) and include a recovery record, therefore the script must be executed from the Terminal in order to enter the password.
  • Searches for a "backup" folder in the home directory of the user who runs the script in order to place the tarball and the log file; if it does not exist it creates one with the following structure: '~/backup/opera/opera_tarballs/' & '~/backup/opera/logs/'.
  • The generated log goes deep enough to provide general info about which directories and files were backed up
    but in order to avoid huge log files it will not display every file of the largest and deepest subdirectories (like the ".mbs" files present in the mail directory). If there's an error during the backup process, the script will write a general error message to the log file.
  • All archieves and log files older than 30 days will be removed from the '~/backup/opera' directory. It can be changed to any other value that better suits your needs. For example, if you (or cron) run the script every day a better value would be 7 or 5.


The script:
#!/bin/bash 
#
# ***IMPORTANT***
#
#The script does the following:
#
# - Backs up the opera profile directory of the user who runs the script (it assumes the path is ~/.opera) excluding the cache and images folders 
#and ***including the mail directory***. The mail directory can be excluded uncomenting the variable and adding an exception to 'tar' (see below).
#
# - By default it creates a tarball (tar.bz2) and a log file every time the script is run. However an option to use RAR instead of tar is provided too (see below).
#RAR INFO:
#The RAR command will encrypt the archive (both file data and headers) and include a recovery record, therefore the script must be executed from the Terminal in order to enter the password. 
#
# - Searches for a "backup" folder in the home directory of the user who runs the script in order to place the tarball and the log file; 
#if it does not exist it creates one with the following structure: '~/backup/opera/opera_tarballs/' & '~/backup/opera/logs/'.
#
# - The generated log goes deep enough to provide general info about which directories and files were backed up 
#but in order to avoid huge log files it will not display every file of the largest and deepest subdirectories (like the ".mbs" files present in the mail directory). 
#If there's an error during the backup process, the script will write a general error message to the log file.
#
# - All tarballs and log files older than 30 days will be removed from the  '~/backup/opera' directory. 
#It can be changed to any other value that better suits your needs (see below). 
#For example, if you (or cron) run the script every day a better value would be 7 or 5. 
#
####################
                                         
fro_di="${HOME}/.opera"
dest="${HOME}/backup/opera/opera_tarballs/opera_backup"
ex_ima="${HOME}/.opera/images"
cac_a="${HOME}/.opera/cache4"
cac_b="${HOME}/.opera/cacheOp"
dat_ext=$(date +%Y_%m_%d__%X).tar.bz2 #Comment this line in order to use RAR instead of tar.
#dat_ext=$(date +%Y_%m_%d__%X).rar #Uncomment this line in order to use RAR instead of tar.
result="${dest}${dat_ext}"
back_fo="${HOME}/backup/"
back_op_fo="${HOME}/backup/opera/"
back_optar_fo="${HOME}/backup/opera/opera_tarballs/"
log_fo="${HOME}/backup/opera/logs/"
log_fi="${HOME}/backup/opera/logs/opera_backup_log$(date +%Y_%m_%d__%X).log"
log_out="------------------$(date +%Y_%m_%d______%X) ---------- Backup process has started..."
log_out_ok="-----------------Backup completed.  ${result} created------" 
log_out_er="Backup__ERROR__--- $(date +%Y_%m_%d___%X)!!!"
time_mod=30 # Backup archieves and log files older than 30 days will be removed. It can be changed to any other value that better suits your needs.                                         
#ex_mai="${HOME}/.opera/mail" 
#Uncomment the line above if you want to exclude the mail directory from the backup process and add  --exclude=${ex_mai} to the tar command below or -x${x_mai} if using RAR.
#################### 
                        
function ma_di () {

if [ ! -d "${1}" ];then

          mkdir ${1}
fi
}

ma_di ${back_fo}
ma_di ${back_op_fo}
ma_di ${back_optar_fo}
ma_di ${log_fo}

if [ ! -w "${log_fi}" ];then

          touch ${log_fi}
fi    
     
echo ${log_out} >> ${log_fi}
    
tar --exclude=${ex_ima} --exclude=${cac_a}  --exclude=${cac_b} -cvjf ${dest}${dat_ext} ${fro_di} | uniq -c --check-chars=35 >> ${log_fi}
#Comment the line above in order to use RAR instead of tar.

#rar a -m5 -hp -r -rr ${dest}${dat_ext} ${fro_di} -x${ex_ima} -x${cac_a} -x${cac_b} | uniq -c --check-chars=35 >> ${log_fi}
#Uncomment the line above in order to use RAR instead of tar.

if [ -f "${result}" ]; then

          echo "Backup completed.  ${result} created"
          echo ${log_out_ok} >> ${log_fi}
else
          echo "Backup error"
          echo ${log_out_er} >> ${log_fi} 
          exit 1
fi

function rem_ol () {

for old in `find ${1} -mtime +${time_mod}`;do

          rm ${old}
done
}

rem_ol ${log_fo}
rem_ol ${back_optar_fo}

exit 0


Download:
opera_backup_bash_script.tar.bz2

10. April 2007, 09:53:43

vvoody

Posts: 110

Well done.It's quite useful.

Forums » Opera for Windows/Mac/Linux » Opera for *nix - Linux/FreeBSD