mobi_backup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
mobi_backup [20.07.2018 06:58] Pascal Sutermobi_backup [15.03.2022 16:23] (current) – [Error due to old flock version] Pascal Suter
Line 1: Line 1:
 ====== MOBI Backup (rsync wrapper) ====== ====== MOBI Backup (rsync wrapper) ======
-like probably every Linux admin, I eventually came to the point where I felt like it was time to write **M**y **O**wn **B**ackup **I**mplementation as an rsync wrapper to do some backups. This script is in its funcitonality very similar to what rubi does: it creates a new sub-directory with the date of the backup as directory each time the backup is run. every backup directory contains a full backup of the source, but only the difference since the last backup does actually need to be synced. when i say the difference i mean files that have changed.. yes, files, not blocks! so if your 2GB log file gets a new line, 2GB will have to be downloaded. but if your file does not change, it will be hard-linked to the previous backup and therefore nothing needs to be downloaded. +like probably every Linux admin, I eventually came to the point where I felt like it was time to write **M**y **O**wn **B**ackup **I**mplementation as an rsync wrapper to do some backups. This script is in its funcitonality very similar to what [[backup_with_rubi|rubi]] does: it creates a new sub-directory with the date of the backup as directory each time the backup is run. every backup directory contains a full backup of the source, but only the difference since the last backup does actually need to be synced. when i say the difference i mean files that have changed.. yes, files, not blocks! so if your 2GB log file gets a new line, 2GB will have to be downloaded. but if your file does not change, it will be hard-linked to the previous backup and therefore nothing needs to be downloaded. 
  
 to achieve this, I use rsync's ''--link-dst'' option.  to achieve this, I use rsync's ''--link-dst'' option. 
Line 6: Line 6:
 In most cases, this proves to be simple but still efficient enough, rather than trying block-level incrementals.  In most cases, this proves to be simple but still efficient enough, rather than trying block-level incrementals. 
  
-at the end of a successful backupa rotation is made and old backups are being deleted where appropriatealso a summary email is sent to the admin+One specialty of MOBI, and the main reason for writing this script in the first place, is that it runs multiple backups in parallelIt has sort of its own queue manager to do that. It will take all Job Definitions and put them in the queue and it will then run multiple in parallel. The number of parallel backup processes can be defined by setting the ''PARALLELPROCS=8'' variable in the script. Default is ''8''
  
-so here is the script.. use it at your own risk and let me know if you find bugs or have contributions to makesimply send me an email to contact at psuter dot ch+The advantage of running multiple backup jobs at once is, that you can usually reach a much higher overall throughput with multiple rsyncs running in parallel than running them one after the other because rsync is single threaded and the overhead for ssh and file checking etcis hugeSo it usually makes no sense to wait for one host to complete before backing up a second host\\ 
 +You could also define multiple backup jobs for the same host but different directories on the host, to increase the speed of large backups
  
 +if you are looking for a solution to speed up an rsync copy process with parallel rsync invocations, take a look at my [[parallel_rsync]] article. Sadly the function I wrote there does not help in speeding up incremental backups at all (in contrary, it adds more overhead and hence makes an incremental backup even slower!). 
 +
 +at the end of a successful backup, a rotation is made and old backups are being deleted where appropriate. also a summary email is sent to the admin. 
 +===== Configuration =====
 to configure, simply edit the lines or add more blocks after the to configure, simply edit the lines or add more blocks after the
 <code>############################################################## <code>##############################################################
Line 18: Line 23:
  
 the script will write a hidden file named .lastdst to the backup base directory for each backup job. this file always contains the folder name of the sub directory of the last successful backup.  the script will write a hidden file named .lastdst to the backup base directory for each backup job. this file always contains the folder name of the sub directory of the last successful backup. 
 +
 +===== Logs and Debugging =====
 +the script writes multiple log files. First of all it writes a new log file for every invocation to /tmp/<date-time>.log. this is a general log which contains information printed by the "queue manager". It then writes two log files for each backup job it runs. these can be found in the same directory where these backup jobs are stored (defined by ''BASEDST'') again with the start date and time of the job. one ends on ''log'' the other one ends on ''.err''. the ''.log'' file contains the standard-output of the process and the ''err'' file contains the standard-error output. so if copying a file failed for example it should be listed in the ''err'' file. 
 +
 +===== Known Issues =====
 +On systems with old rsync versions (i.e. 3.0.6) and if your data contains extended Attributes or ACL's you may get lots of ''Missing abbreviated xattr value, trusted.SGI_ACL_DEFAULT'' messages in your logs. Also your backup may get bloatet because files with ACL's or extended Attributes are constantly re-downloaded. This is due to some issues with ACL and Xattr support in old rsync versions. Either update to a newer version of Rsync or disable ACL and XATTR support by removing the ''-X'' and ''-A'' options in the bash script, that means, replace ''rsync -aAHXv'' with ''rsync -aHv''. This will disable ACL and XATTR support which menans, such attributes won't be backed up. 
 +===== the script =====
 +so here is the script.. use it at your own risk and let me know if you find bugs or have contributions to make. simply send me an email to contact at psuter dot ch. 
  
 <code bash mobi.sh> <code bash mobi.sh>
Line 24: Line 37:
 # no use without prior permission from DALCO AG # no use without prior permission from DALCO AG
 # pascal.suter@dalco.ch  # pascal.suter@dalco.ch 
 +# the latest version and some documentation for this script can be found on http://wiki.psuter.ch/doku.php?id=mobi_backup
 # version 1.1  # version 1.1 
 # replaced ps aux | grep rsync style locking with flock locking to allow this script to run on servers that use rsync for other stuff as well :)  # replaced ps aux | grep rsync style locking with flock locking to allow this script to run on servers that use rsync for other stuff as well :) 
Line 29: Line 43:
 # added eval in front of rsync call to properly evaluate the $OPTIONS variable contents when running the command # added eval in front of rsync call to properly evaluate the $OPTIONS variable contents when running the command
 # version 1.3 # version 1.3
-# moved log from rsyncs stderr to a separate .err file which makes finding the relevant error messages in the rsync output alto easier +# moved log from rsyncs stderr to a separate .err file which makes finding the relevant error messages in the rsync output alot easier 
  
 report() { report() {
Line 333: Line 347:
 cat /tmp/backupReport.txt | mail -s "$SUBJECT: $REPORT_SUBJECT" "$REPORT_RECIPIENTS" cat /tmp/backupReport.txt | mail -s "$SUBJECT: $REPORT_SUBJECT" "$REPORT_RECIPIENTS"
 rm -f /tmp/backupReport.txt rm -f /tmp/backupReport.txt
 +</code>
 +===== run daily =====
 +in order to run the backup daily, run ''crontab -e'' as user ''root'' and enter a new line like this one here: 
 +  00 1 * * * /opt/mobi.sh > /dev/null 2>&1
 +using the redirects of both stdout and stderr to ''/dev/null'' makes sure you don't receive two emails on every backup where one would come through cron. all the necessary info is logged and the summary is emailaed directly without needing cron to send us any info. 
 +
 +===== Error due to old flock version =====
 +when this script is run on an older linux distribution such as CentOS 6.5 for example, the provided version of flock is too old to know the ''-E'' option which specifies an exit code in case the lock could not be acquired. in such a situation you can patch the mobi.sh script using this command: 
 +  sed -i 's/-E 66 //' mobi.sh
 +this will make the script work on those systems. however, since now the exit code of flock is ''1'' when it can't acquire a lock the error message displayed in such a case might be a bit misleading, as it is the same as displayed in case of a syntax error in the rsync call. so keep that in mind when debugging such cases. 
 +
 +===== Migration from RUBI =====
 +Since i was using [[backup_with_rubi|rubi]] before on many systems (private and customer systems) I'll provide a quick migration guide for those who want to migrate from rubi to mobi: 
 +
 +  - download the above script and save it to ''/opt/backup/backup.sh'' 
 +  - edit the script
 +    - adjust the ''REPORT_RECIPIENTS'' variable as needed
 +    - under the ''Backup Job Definitions start here'' write a new block for every backup. 
 +      - ''BACKUPNAME'' can be set as you like. it will be mentioned in the backup report. Usually coming from RUBI this will be set to the same value as ''SRCHOST'' was in RUBI
 +      - ''SOURCE'' needs to list all directories like ''SRCPART'' did, but they need to be prepended by the hostname, so ''SRCPART=/ /boot'' with ''SRCHOST=mysrv'' would be migrated into ''SOURCE=mysrv:/ mysrv:/boot''
 +      - ''BASEDST'' can be copy/pasted from rubi 1:1 
 +      - ''KEEPC'' could be set to the same value as ''KEEPD''
 +  - to go the backup directory for each host and run this command <code>basename $(<lastdst) | tr -d ":" > .lastdst</code>
 +  - remove the ":" in the directory name of the last backup that is written in ''lastdst'' like so: <code>mv 2018.04.01-00\:09 2018.04.01-0009</code>
 +  - cleanup old log files and ''lastdst'' file and whatever else there might be laying around in this folder. 
 +  - remember to come back and delete the old backups when it's time. old RUBI backups won't be rotated using mobi, this needs to be done manually. mobi will only include backups into the rotation for which it finds a log file of a successful backup job. 
  • mobi_backup.1532062703.txt.gz
  • Last modified: 20.07.2018 06:58
  • by Pascal Suter