Changes between Version 3 and Version 4 of S3QLBackup
- Timestamp:
- Oct 8, 2015, 1:31:37 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3QLBackup
v3 v4 10 10 11 11 {{{ 12 #!bash 12 13 #!/bin/bash 13 14 … … 19 20 # same name with a list of directories to backup exists 20 21 # in /etc/s3ql 22 CONFIG_DIR="/etc/s3q" 23 # S3 server URL 24 SERVER="s3c://s.qstack.advania.com:443" 25 # mount directory for s3ql file systems 26 MOUNT="/media/s3ql" 27 # optional base source directory for for files to 28 # backup, this is used because all the servers are 29 # sshfs mounted at /media/server-name 30 SOURCE="/media/$BUCKET" 31 # rsync command 32 RSYNC="rsync -aHAXx --delete-during --delete-excluded --partial -v" 21 33 22 34 # Check for bucket name / directory on standard input … … 29 41 fi 30 42 31 # Backup destination (storage url)32 storage_url="s3c://s.qstack.advania.com:443/$BUCKET"33 34 43 # Check that a list of diectories to backup exists at 35 # /etc/s3ql/$BUCKET36 if [[ ! -f " /etc/s3ql/$BUCKET" ]]; then37 echo "You need to create /etc/s3ql/$BUCKET with a list of directories to backup"44 # $CONFIG_DIR/$BUCKET 45 if [[ ! -f "$CONFIG_DIR/$BUCKET" ]]; then 46 echo "You need to create $CONFIG_DIR/$BUCKET with a list of directories to backup" 38 47 exit 39 48 else 40 BACKUP_LIST=" /etc/s3ql/$BUCKET"49 BACKUP_LIST="$CONFIG_DIR/$BUCKET" 41 50 fi 42 51 52 # The following two commands are commented out as the mnt-s3ql script covers 53 # this and is run via cron before this script is run 54 43 55 # Recover cache if e.g. system was shut down while fs was mounted 44 fsck.s3ql --backend-options="dumb-copy" --batch "$storage_url"56 #fsck.s3ql --backend-options="dumb-copy" --batch "$SERVER/$BUCKET" 45 57 46 # Create a temporary mountpoint and mount file system 47 mountpoint="/tmp/s3ql_backup_$$" 48 mkdir "$mountpoint" 49 mount.s3ql --backend-options="dumb-copy" "$storage_url" "$mountpoint" 50 51 # Make sure the file system is unmounted when we are done 52 # Note that this overwrites the earlier trap, so we 53 # also delete the lock file here. 54 trap "cd /; umount.s3ql '$mountpoint'; rmdir '$mountpoint'; rm '$lock'" EXIT 58 # Mount file system 59 #mount.s3ql --backend-options="dumb-copy" "$SERVER/$BUCKET" "$MOUNT/$BUCKET" 55 60 56 61 # Figure out the most recent backup 57 cd "$ mountpoint"58 last_backup=`python <<EOF62 cd "$MOUNT/$BUCKET" 63 LAST_BACKUP=`python <<EOF 59 64 import os 60 65 import re … … 65 70 66 71 # Duplicate the most recent backup unless this is the first backup 67 new_backup=`date "+%Y-%m-%d_%H:%M:%S"`68 if [ -n "$ last_backup" ]; then69 echo "Copying $ last_backup to $new_backup..."70 s3qlcp "$ last_backup" "$new_backup"72 NEW_BACKUP=`date "+%Y-%m-%d_%H:%M:%S"` 73 if [ -n "$LAST_BACKUP" ]; then 74 echo "Copying $LAST_BACKUP to $NEW_BACKUP..." 75 s3qlcp "$LAST_BACKUP" "$NEW_BACKUP" 71 76 72 77 # Make the last backup immutable 73 78 # (in case the previous backup was interrupted prematurely) 74 s3qllock "$ last_backup"79 s3qllock "$LAST_BACKUP" 75 80 fi 76 81 … … 81 86 # --exclude /.thumbnails/ \ 82 87 # --exclude /tmp/ \ 83 # "/home/my_username/" "./$ new_backup/"88 # "/home/my_username/" "./$NEW_BACKUP/" 84 89 85 if [[ -d $mountpoint]]; then86 if [[ ! -d "$ mountpoint/$new_backup" ]]; then87 echo "$ mountpoint/$new_backupdoesn't exist so creating it"88 mkdir -p $mountpoint/$new_backup90 if [[ -d "$MOUNT/$BUCKET" ]]; then 91 if [[ ! -d "$MOUNT/$BUCKET/$NEW_BACKUP" ]]; then 92 echo "$MOUNT/$BUCKET/$NEW_BACKUP doesn't exist so creating it" 93 mkdir -p "$MOUNT/$BUCKET/$NEW_BACKUP" 89 94 fi 90 95 for dir in $(<${BACKUP_LIST}); do 91 mkdir -p "$ mountpoint/$new_backup$dir/"92 rsync -aHAXx --delete-during --delete-excluded --partial -v "/media/$BUCKET$dir/" "$mountpoint/$new_backup$dir/"96 mkdir -p "$MOUNT/$BUCKET/$NEW_BACKUP$dir/" 97 $RSYNC "$SOURCE$dir/" "$MOUNT/$BUCKET/$NEW_BACKUP$dir/" 93 98 done 94 99 else 95 echo "$ mountpointdoesn't exist - something has gone horribly wrong"100 echo "$MOUNT/$BUCKET doesn't exist - something has gone horribly wrong" 96 101 exit 97 102 fi 98 103 99 104 # Make the new backup immutable 100 s3qllock "$ new_backup"105 s3qllock "$NEW_BACKUP" 101 106 102 107 # Expire old backups … … 106 111 # installed an S3QL package for your distribution, this script *may* 107 112 # be installed, and it *may* also not have the .py ending. 108 expire_backups --use-s3qlrm 1 7 14 31 90 180 360113 #expire_backups --use-s3qlrm 1 7 14 31 90 180 360 109 114 }}}