From 0ea0f3f12325cb0e645c0b22bb63cedad063f4b7 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Tue, 31 Aug 2010 12:28:11 +0200 Subject: [PATCH] config structure setup script prototype --- debian/install | 3 +++ defaults.conf | 8 +++++++ remote-backup | 39 +++++++++++++++++++--------------- remote-backup.conf | 4 ---- remote-backup.example.conf | 8 +++++++ remote-backup.example.excludes | 1 + 6 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 debian/install create mode 100644 defaults.conf delete mode 100644 remote-backup.conf create mode 100644 remote-backup.example.conf create mode 100644 remote-backup.example.excludes diff --git a/debian/install b/debian/install new file mode 100644 index 0000000..44ac724 --- /dev/null +++ b/debian/install @@ -0,0 +1,3 @@ +remote-backup /usr/bin/ +defaults /etc/remote-backup/ +remote-backup.example.* /usr/share/remote-backup diff --git a/defaults.conf b/defaults.conf new file mode 100644 index 0000000..41f21e3 --- /dev/null +++ b/defaults.conf @@ -0,0 +1,8 @@ +REMOUNT=false +MOUNT_DEVICE=none +SNAPSHOT_RW=/var/backups +REMOTE_LOCATION="" +EXCLUDES=/dev/null +DEST="" +MAX_ROTATE=7 +BWLIMIT=0 # kBps diff --git a/remote-backup b/remote-backup index 0eadba1..74a3758 100755 --- a/remote-backup +++ b/remote-backup @@ -62,6 +62,8 @@ fi source /etc/remote-backup.conf +echo "Debut de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" + # ------------- the script itself -------------------------------------- # make sure we're running as root @@ -85,26 +87,26 @@ fi # rotating snapshots of /home (fixme: this should be more general) # step 1: delete the oldest snapshot, if it exists: -if [ -d $SNAPSHOT_RW/home/hourly.3 ] +if [ -d $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} ] then - $RM -rf $SNAPSHOT_RW/home/hourly.3 + $RM -rf $SNAPSHOT_RW/$DEST/daily.${MAX_ROTATE} fi # step 2: shift the middle snapshots(s) back by one, if they exist -if [ -d $SNAPSHOT_RW/home/hourly.2 ] -then - $MV $SNAPSHOT_RW/home/hourly.2 $SNAPSHOT_RW/home/hourly.3 -fi -if [ -d $SNAPSHOT_RW/home/hourly.1 ] -then - $MV $SNAPSHOT_RW/home/hourly.1 $SNAPSHOT_RW/home/hourly.2 -fi +for backup_number in $(seq $((${MAX_ROTATE}-1)) -1 1) +do + if [ -d $SNAPSHOT_RW/$DEST/daily.${backup_number} ] + then + $MV $SNAPSHOT_RW/$DEST/daily.${backup_number} \ + $SNAPSHOT_RW/$DEST/daily.$((${backup_number}+1)) + fi +done # step 3: make a hard-link-only (except for dirs) copy of the latest snapshot, # if that exists -if [ -d $SNAPSHOT_RW/home/hourly.0 ] +if [ -d $SNAPSHOT_RW/$DEST/daily.0 ] then - $CP -al $SNAPSHOT_RW/home/hourly.0 $SNAPSHOT_RW/home/hourly.1 + $CP -al $SNAPSHOT_RW/$DEST/daily.0 $SNAPSHOT_RW/$DEST/daily.1 fi # step 4: rsync from the system into the latest snapshot (notice that @@ -112,15 +114,16 @@ fi # is unlinked first. If it were not so, this would copy over the other # snapshot(s) too! $RSYNC \ - -va \ + -a \ --delete \ --delete-excluded \ --exclude-from="$EXCLUDES" \ - /home/ \ - $SNAPSHOT_RW/home/hourly.0 + --bwlimit=$BWLIMIT \ + ${REMOTE_LOCATION} \ + $SNAPSHOT_RW/$DEST/daily.0 -# step 5: update the mtime of hourly.0 to reflect the snapshot time -$TOUCH $SNAPSHOT_RW/home/hourly.0 +# step 5: update the mtime of daily.0 to reflect the snapshot time +$TOUCH $SNAPSHOT_RW/$DEST/daily.0 # and thats it for home. @@ -134,3 +137,5 @@ then exit fi fi + +echo "Fin de backup de ${REMOTE_LOCATION} vers ${SNAPSHOT_RW}/${DEST}/ a $(date)" diff --git a/remote-backup.conf b/remote-backup.conf deleted file mode 100644 index bb6ea28..0000000 --- a/remote-backup.conf +++ /dev/null @@ -1,4 +0,0 @@ -REMOUNT=false -MOUNT_DEVICE=/dev/hdb1; -SNAPSHOT_RW=/root/snapshot; -EXCLUDES=/usr/local/etc/backup_exclude; diff --git a/remote-backup.example.conf b/remote-backup.example.conf new file mode 100644 index 0000000..608eeb5 --- /dev/null +++ b/remote-backup.example.conf @@ -0,0 +1,8 @@ +REMOUNT=__setbackup__REMOUT__ +MOUNT_DEVICE=__setbackup__DEVICE__ +SNAPSHOT_RW=__setbackup__SNAPSHOT__ +REMOTE_LOCATION="__setbackup__REMOTE__ +EXCLUDES=__setbackup__EXCLUDES__ +DEST=__setbackup__DEST__ +MAX_ROTATE=__setbackup__ROTATE__ +BWLIMIT=__setbackup__BWLIMIT__ # kBps diff --git a/remote-backup.example.excludes b/remote-backup.example.excludes new file mode 100644 index 0000000..4fca784 --- /dev/null +++ b/remote-backup.example.excludes @@ -0,0 +1 @@ +mysql-log