[[PageOutline(2-5, Table of Contents, floated)]] = S3QL Backup Script = Following is a modified version of the [http://www.rath.org/s3ql-docs/contrib.html#s3-backup-sh s3_backup.sh] script which which was provided by the Debian package at `/usr/share/doc/s3ql/examples/s3ql_backup.sh`. It expects a `/etc/s3ql/SERVERNAME` file listing directories to be backed up for each server and the SERVERNAME is expected to match the bucket name. == s3ql_backup == {{{ #!bash #!/bin/bash # Abort entire script if any command fails #set -e # This script assumes that bucketname and directory under # /media match and is also assumes that a file, with the # same name with a list of directories to backup exists # in /etc/s3ql CONFIG_DIR="/etc/s3ql" # S3 server URL S3QL_SERVER="s3c://s.qstack.advania.com:443" # rsync command RSYNC="rsync -aHAXx --delete-during --delete-excluded --partial -v" # mount directory for s3ql file systems S3QL_MOUNT="/media/s3ql" # mount directory for sshfs file systems SSHFS_MOUNT="/media/sshfs" # directory where the scripts this script depends on are located SCRIPT_DIR="/usr/local/bin" # This script uses lockfile which comes with procmail # lockfile lines commented out, to enable see lines starting with ## ##LOCKFILE_BINARY="/usr/bin/lockfile" ##LOCKFILE="/var/run/lock/$(basename $0).lock" #echo "LOCKFILE: $LOCKFILE" # Seconds between unmount attempts SLEEP="15" # Mins after rsync before umnt it attempted LONG_SLEEP="5m" # echo to standard out function echoerr() { echo "$@" 1>&2; } # Check that the script is being run by root if [[ "$(id -u)" != "0" ]] ; then echoerr "You must run '$0' as root or via sudo" exit 1 fi # Test if the lockfile binary can be found ##if [[ ! -e "$LOCKFILE_BINARY" ]]; then ## echo "$LOCKFILE_BINARY not found, please install the procmail package." ## exit 1 ##fi # check the $S3QL_MOUNT directory exists if [[ ! -d "$S3QL_MOUNT" ]]; then echoerr "$S3QL_MOUNT doesn't exist" exit 1 fi # check the $SSHFS_MOUNT directory exists if [[ ! -d "$SSHFS_MOUNT" ]]; then echoerr "$SSHFS_MOUNT doesn't exist" exit 1 fi # Check for bucket name / directory on standard input if [[ $1 ]]; then BUCKET="$1" elif [[ ! "$1" ]]; then echo "Type the bucketname and then [ENTER]:" read bucket BUCKET="$bucket" fi # check if the Transport endpoint is not connected if $SCRIPT_DIR/s3ql_endpoint_check ; then echo "No problem with disconnected endpoints" else echoerr "Problem with a disconnected endpoint" exit 1 fi # Check that a list of directories to backup exists at # $CONFIG_DIR/$BUCKET if [[ ! -f "$CONFIG_DIR/$BUCKET" ]]; then echoerr "You need to create $CONFIG_DIR/$BUCKET with a list of directories to backup" exit 1 else BACKUP_LIST="$CONFIG_DIR/$BUCKET" fi # sshfs mounted at /media/server-name SSHFS_SOURCE="$SSHFS_MOUNT/$BUCKET" if [[ -d "$SSHFS_SOURCE" ]]; then # mount the sshfs if $SCRIPT_DIR/mnt-sshfs "$BUCKET" ; then echo "Success mounting $SSHFS_MOUNT/$BUCKET" else echoerr "Problem mounting $SSHFS_SOURCE" exit 1 fi else echoerr "$SSHFS_SOURCE doesn't exist" exit 1 fi # check the bucket exists if [[ -d "$S3QL_MOUNT/$BUCKET" ]]; then # mount the s3ql directory if $SCRIPT_DIR/mnt-s3ql "$BUCKET" ; then echo "Success mounting $S3QL_MOUNT/$BUCKET" else echoerr "Problem mounting $S3QL_MOUNT/$BUCKET" exit 1 fi else echoerr "$S3QL_MOUNT/$BUCKET doesn't exist" exit 1 fi # if the $LOCKFILE exists then exit # the lockfile is read only # the timeout is set to 2 hours (7200 secs) # if the lockfile is older than this it will be removed ##DATE=$(date -R) #$LOCKFILE_BINARY -r 1 -l 21600 $LOCKFILE || { echo "$LOGFILE exists exiting $DATE" ; exit 23 ; } ##$LOCKFILE_BINARY -r 1 -l 7200 $LOCKFILE || \ ## { echo "$LOCKFILE exists exiting $DATE" ; exit 1 ; } # Figure out the most recent backup cd "$S3QL_MOUNT/$BUCKET" LAST_BACKUP=`python <&1 | grep "Transport endpoint is not connected" | awk '{ print $2 }' | tr -d '‘' | tr -d '’:') if [[ "$S3QL_DISCONNECTED_ENDPOINTS" ]]; then for s3qlfs in $S3QL_DISCONNECTED_ENDPOINTS; do if fusermount -u -z "${s3qlfs}" ; then echo "Success unmounting ${s3qlfs}" exit 0 else echo "Problem unmounting ${s3qlfs}, consider using: killall -9 mount.s3ql" exit 1 fi done fi }}}