Changes between Version 3 and Version 4 of S3QLBackup


Ignore:
Timestamp:
Oct 8, 2015, 1:31:37 PM (3 years ago)
Author:
chris
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • S3QLBackup

    v3 v4  
    1010
    1111{{{
     12#!bash
    1213#!/bin/bash
    1314
     
    1920# same name with a list of directories to backup exists
    2021# in /etc/s3ql
     22CONFIG_DIR="/etc/s3q"
     23# S3 server URL
     24SERVER="s3c://s.qstack.advania.com:443"
     25# mount directory for s3ql file systems
     26MOUNT="/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
     30SOURCE="/media/$BUCKET"
     31# rsync command
     32RSYNC="rsync -aHAXx --delete-during --delete-excluded --partial -v"
    2133
    2234# Check for bucket name / directory on standard input
     
    2941fi
    3042
    31 # Backup destination  (storage url)
    32 storage_url="s3c://s.qstack.advania.com:443/$BUCKET"
    33 
    3443# Check that a list of diectories to backup exists at
    35 # /etc/s3ql/$BUCKET
    36 if [[ ! -f "/etc/s3ql/$BUCKET" ]]; then
    37   echo "You need to create /etc/s3ql/$BUCKET with a list of directories to backup"
     44# $CONFIG_DIR/$BUCKET
     45if [[ ! -f "$CONFIG_DIR/$BUCKET" ]]; then
     46  echo "You need to create $CONFIG_DIR/$BUCKET with a list of directories to backup"
    3847  exit
    3948else
    40   BACKUP_LIST="/etc/s3ql/$BUCKET"
     49  BACKUP_LIST="$CONFIG_DIR/$BUCKET"
    4150fi
    4251
     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
    4355# 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"
    4557
    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"
    5560
    5661# Figure out the most recent backup
    57 cd "$mountpoint"
    58 last_backup=`python <<EOF
     62cd "$MOUNT/$BUCKET"
     63LAST_BACKUP=`python <<EOF
    5964import os
    6065import re
     
    6570
    6671# 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" ]; then
    69     echo "Copying $last_backup to $new_backup..."
    70     s3qlcp "$last_backup" "$new_backup"
     72NEW_BACKUP=`date "+%Y-%m-%d_%H:%M:%S"`
     73if [ -n "$LAST_BACKUP" ]; then
     74    echo "Copying $LAST_BACKUP to $NEW_BACKUP..."
     75    s3qlcp "$LAST_BACKUP" "$NEW_BACKUP"
    7176
    7277    # Make the last backup immutable
    7378    # (in case the previous backup was interrupted prematurely)
    74     s3qllock "$last_backup"
     79    s3qllock "$LAST_BACKUP"
    7580fi
    7681
     
    8186#    --exclude /.thumbnails/ \
    8287#    --exclude /tmp/ \
    83 #    "/home/my_username/" "./$new_backup/"
     88#    "/home/my_username/" "./$NEW_BACKUP/"
    8489
    85 if [[ -d $mountpoint ]]; then
    86   if [[ ! -d "$mountpoint/$new_backup" ]]; then
    87     echo "$mountpoint/$new_backup doesn't exist so creating it"
    88     mkdir -p $mountpoint/$new_backup
     90if [[ -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"
    8994  fi
    9095  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/"
    9398  done
    9499else
    95   echo "$mountpoint doesn't exist - something has gone horribly wrong"
     100  echo "$MOUNT/$BUCKET doesn't exist - something has gone horribly wrong"
    96101  exit
    97102fi
    98103
    99104# Make the new backup immutable
    100 s3qllock "$new_backup"
     105s3qllock "$NEW_BACKUP"
    101106
    102107# Expire old backups
     
    106111# installed an S3QL package for your distribution, this script *may*
    107112# be installed, and it *may* also not have the .py ending.
    108 expire_backups --use-s3qlrm 1 7 14 31 90 180 360
     113#expire_backups --use-s3qlrm 1 7 14 31 90 180 360
    109114}}}