Last active
February 7, 2016 20:54
-
-
Save pol/c5338d47970a30d4d730 to your computer and use it in GitHub Desktop.
Novel (?) incremental backup using rsync without hardlinks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # | |
| # Novel (?) rsync incremental backup without hardlinks | |
| # Pol Llovet <pol.llovet@montana.edu> | |
| case "$2" in | |
| '') | |
| ;& | |
| '-h') | |
| ;& | |
| '--help') | |
| echo $"Usage: $0 {SRC_PATH} {DEST_PATH}" | |
| echo $" Full paths required." | |
| exit 1 | |
| ;; | |
| *) | |
| backup_dir=$2 | |
| source_dir=$1 | |
| ;; | |
| esac | |
| # Names | |
| backup_name=`date +%Y-%m-%d-%H%M%S` | |
| backup_increment_dir="$backup_dir/${backup_name//-//}" | |
| # Supporting Dirs | |
| manifest_dir="$backup_dir/manifest" | |
| # Logs & Manifest | |
| log="$backup_dir/current.log" | |
| backup_manifest="$manifest_dir/$backup_name.manifest" | |
| backup_log="$backup_dir/$backup_name.log" | |
| # Rsync options | |
| check_current="--dry-run -Wiah . $backup_dir/current" | |
| create_increment="-Wah --stats --compare-dest=$backup_dir/current . $backup_increment_dir" | |
| update_current="-Wah --delete --stats . $backup_dir/current" | |
| # make sure target dirs exist | |
| if [ ! -d $backup_dir/current ]; then mkdir -p $backup_dir/current; fi | |
| if [ ! -d $manifest_dir ]; then mkdir -p $manifest_dir; fi | |
| echo "========== $backup_name ==========" >> $log | |
| cd $source_dir | |
| rsync $check_current > $backup_manifest | |
| if [ -s $backup_manifest ]; then | |
| 2>&1 rsync $create_increment > $backup_log | |
| if [ $? != 0 ]; then echo "Errors in increment creation! See $backup_log."; fi | |
| 2>&1 rsync $update_current >> $log | |
| if [ $? != 0 ]; then echo "Errors in current backup update! See $log."; fi | |
| tar --remove-files -czf $backup_dir/$backup_name.tgz $backup_log $backup_increment_dir | |
| else | |
| # no changes, nothing to do, rm the empty manifest | |
| rm -f $backup_manifest | |
| echo "No changes to $source_dir. Nothing to back up." | |
| fi | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because of this http://stackoverflow.com/questions/13993236/why-rsync-uses-mkdir-without-p-option
i suggest to add after
if [ ! -d $backup_dir/current ]; then mkdir -p $backup_dir/current; fiif [ ! -d $manifest_dir ]; then mkdir -p $manifest_dir; fiThis line to avoid rsync errors complaining about "rsync: mkdir failed: No such file or directory (2)"
if [ ! -s $backup_increment_dir ]; then mkdir -p $backup_increment_dir; fi