Changes between Version 5 and Version 6 of S3QLBackup


Ignore:
Timestamp:
Oct 14, 2015, 2:51:11 PM (3 years ago)
Author:
chris
Comment:

Updated script

Legend:

Unmodified
Added
Removed
Modified
  • S3QLBackup

    v5 v6  
    2323# S3 server URL
    2424SERVER="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
    2925# rsync command
    3026RSYNC="rsync -aHAXx --delete-during --delete-excluded --partial -v"
     27# mount directory for s3ql file systems
     28S3QL_MOUNT="/media/s3ql"
     29# mount directory for sshfs file systems
     30SSHFS_MOUNT="/media/sshfs"
     31
     32# check the $S3QL_MOUNT directory exists
     33if [[ ! -d "$S3QL_MOUNT" ]]; then
     34  echo "$S3QL_MOUNT doesn't exist"
     35  exit 1
     36fi
     37
     38# check the $SSHFS_MOUNT directory exists
     39if [[ ! -d "$SSHFS_MOUNT" ]]; then
     40  echo "$SSHFS_MOUNT doesn't exist"
     41  exit 1
     42fi
    3143
    3244# Check for bucket name / directory on standard input
     
    3951fi
    4052
    41 # sshfs mounted at /media/server-name
    42 SOURCE="/media/$BUCKET"
    43 
    4453# Check that a list of diectories to backup exists at
    4554# $CONFIG_DIR/$BUCKET
    4655if [[ ! -f "$CONFIG_DIR/$BUCKET" ]]; then
    4756  echo "You need to create $CONFIG_DIR/$BUCKET with a list of directories to backup"
    48   exit
     57  exit 1
    4958else
    5059  BACKUP_LIST="$CONFIG_DIR/$BUCKET"
     60fi
     61
     62# sshfs mounted at /media/server-name
     63SSHFS_SOURCE="$SSHFS_MOUNT/$BUCKET"
     64if [[ -d "$SSHFS_SOURCE" ]]; then
     65  # mount the sshfs
     66  mnt-sshfs $BUCKET && \
     67  echo "Success mounting $SSHFS_MOUNT/$BUCKET" || \
     68{ echo "Problem mounting $SSHFS_SOURCE" ; exit 1 ; }
     69else
     70  echo "$SSHFS_SOURCE doesn't exist"
     71  exit 1
     72fi
     73
     74# check the bucket exists
     75if [[ -d "$S3QL_MOUNT/$BUCKET" ]]; then
     76  # mount the s3ql directory
     77  mnt-s3ql $BUCKET  && \
     78  echo "Success mounting $S3QL_MOUNT/$BUCKET" || \
     79{ echo "Problem mounting $S3QL_MOUNT/$BUCKET" ; exit 1 ; }
     80else
     81  echo "$S3QL_MOUNT/$BUCKET doesn't exist"
     82  exit 1
    5183fi
    5284
     
    5890
    5991# Mount file system
    60 #mount.s3ql --backend-options="dumb-copy" "$SERVER/$BUCKET" "$MOUNT/$BUCKET"
     92#mount.s3ql --backend-options="dumb-copy" "$SERVER/$BUCKET" "$S3QL_MOUNT/$BUCKET"
    6193
    6294# Figure out the most recent backup
    63 cd "$MOUNT/$BUCKET"
     95cd "$S3QL_MOUNT/$BUCKET"
    6496LAST_BACKUP=`python <<EOF
    6597import os
     
    72104# Duplicate the most recent backup unless this is the first backup
    73105NEW_BACKUP=`date "+%Y-%m-%d_%H:%M:%S"`
    74 if [ -n "$LAST_BACKUP" ]; then
     106if [[ -n "$LAST_BACKUP" ]]; then
    75107    echo "Copying $LAST_BACKUP to $NEW_BACKUP..."
    76108    s3qlcp "$LAST_BACKUP" "$NEW_BACKUP"
     
    89121#    "/home/my_username/" "./$NEW_BACKUP/"
    90122
    91 if [[ -d "$MOUNT/$BUCKET" ]]; then
    92   if [[ ! -d "$MOUNT/$BUCKET/$NEW_BACKUP" ]]; then
    93     echo "$MOUNT/$BUCKET/$NEW_BACKUP doesn't exist so creating it"
    94     mkdir -p "$MOUNT/$BUCKET/$NEW_BACKUP"
    95   fi
    96   for dir in $(<${BACKUP_LIST}); do
    97     mkdir -p "$MOUNT/$BUCKET/$NEW_BACKUP$dir/"
    98     $RSYNC "$SOURCE$dir/" "$MOUNT/$BUCKET/$NEW_BACKUP$dir/"
    99   done
    100 else
    101   echo "$MOUNT/$BUCKET doesn't exist - something has gone horribly wrong"
    102   exit
     123if [[ ! -d "$S3QL_MOUNT/$BUCKET/$NEW_BACKUP" ]]; then
     124  echo "$S3QL_MOUNT/$BUCKET/$NEW_BACKUP doesn't exist so creating it"
     125  mkdir -p "$S3QL_MOUNT/$BUCKET/$NEW_BACKUP" || \
     126    { echo "Problem making $S3QL_MOUNT/$BUCKET/$NEW_BACKUP" ; exit 1 ; }
    103127fi
     128for dir in $(<${BACKUP_LIST}); do
     129  mkdir -p "$S3QL_MOUNT/$BUCKET/$NEW_BACKUP$dir/" || \
     130    { echo "Problem making $S3QL_MOUNT/$BUCKET/$NEW_BACKUP$dir/" ; exit 1 ; }
     131  $RSYNC "$SSHFS_SOURCE$dir/" "$S3QL_MOUNT/$BUCKET/$NEW_BACKUP$dir/" || \
     132    { echo "Problem with $RSYNC $SSHFS_SOURCE$dir/ $SSHFS_MOUNT/$BUCKET/$NEW_BACKUP$dir/" ; exit 1 ; }
     133done
    104134
    105135# Make the new backup immutable
     
    113143# be installed, and it *may* also not have the .py ending.
    114144#expire_backups --use-s3qlrm 1 7 14 31 90 180 360
     145
     146# unmount s3ql first
     147#umnt-s3ql $BUCKET
     148#umnt-sshfs $BUCKET
    115149}}}