diff options
Diffstat (limited to 'files')
-rwxr-xr-x | files/mount-media | 5 | ||||
-rw-r--r-- | files/sync-backups | 83 | ||||
-rwxr-xr-x | files/sync-media | 47 |
3 files changed, 78 insertions, 57 deletions
diff --git a/files/mount-media b/files/mount-media index c50352f..b643a31 100755 --- a/files/mount-media +++ b/files/mount-media @@ -7,7 +7,7 @@ MEDIA="$1" VOLUME="$2" BASENAME="`basename $0`" -MOUNTPOINT="/media/usb" +MOUNTPOINT="/media/$MEDIA" # Check media config if [ -z "$MEDIA" ]; then @@ -36,8 +36,9 @@ if [ "$BASENAME" == "mount-media" ]; then echo "Checking filesystem..." $sudo fsck -v -y /dev/mapper/$MEDIA && \ echo "Mounting volume at $MOUNTPOINT..." + $sudo mkdir -p $MOUNTPOINT $sudo mount /dev/mapper/$MEDIA $MOUNTPOINT elif [ "$BASENAME" == "umount-media" ]; then - $sudo umount /media/usb && \ + $sudo umount $MOUNTPOINT && \ $sudo cryptsetup luksClose $MEDIA fi diff --git a/files/sync-backups b/files/sync-backups index cb40c77..fc726b3 100644 --- a/files/sync-backups +++ b/files/sync-backups @@ -3,45 +3,62 @@ # sync a removable volume with system backups. # -NODE="$1" -MEDIA="/media/usb" +# Parameters. +BASENAME="`basename $0`" +VOLUME="$1" +MEDIA="/media/$VOLUME" BWLIMIT="2500" IMAGES="/var/data/crypt/" RSYNC="nice -n 19 rsync -avH --delete --bwlimit=$BWLIMIT" -if [ ! -z "$NODE" ]; then - # Get full node hostname. - NODE_HOSTNAME="`cat /var/vservers/$NODE/etc/hostname`" - if [ -z "$NODE_HOSTNAME" ]; then - NODE_HOSTNAME="$NODE" - fi +# Sync backups for a node. +function sync_backups_node { + if [ ! -z "$NODE" ]; then + # Get full node hostname. + NODE_HOSTNAME="`cat /var/vservers/$NODE/etc/hostname`" + if [ -z "$NODE_HOSTNAME" ]; then + NODE_HOSTNAME="$NODE" + fi - # Sync local encrypted backup. - mkdir -p /$MEDIA/$NODE_HOSTNAME/duplicity - $RSYNC /var/vservers/$NODE/var/backups/duplicity/ /$MEDIA/$NODE_HOSTNAME/duplicity/ + # Sync local encrypted backup. + mkdir -p /$MEDIA/$NODE_HOSTNAME/duplicity + $RSYNC /var/vservers/$NODE/var/backups/duplicity/ /$MEDIA/$NODE_HOSTNAME/duplicity/ - # Sync remote backups. - for node in `ls /var/vservers/$NODE/var/backups/remote/`; do - mkdir -p /$MEDIA/$NODE_HOSTNAME/remote/$node - $RSYNC /var/vservers/$NODE/var/backups/remote/$node/ /$MEDIA/$NODE_HOSTNAME/remote/$node/ - done -else - # Sync local encrypted backup. - mkdir -p /$MEDIA/$HOSTNAME/duplicity - $RSYNC /var/backups/duplicity/ /$MEDIA/$HOSTNAME/duplicity/ - - # Sync remote backups. - for node in `ls /var/backups/remote/`; do - mkdir -p /$MEDIA/$HOSTNAME/remote/$node/ - $RSYNC /var/backups/remote/$node/ /$MEDIA/$HOSTNAME/remote/$node/ - done - - # Copy encrypted images. - if [ -d "$IMAGES" ]; then - for image in `find $IMAGES -type f`; do - mkdir -p /$MEDIA/$HOSTNAME/images/`dirname $image` - echo "Copying image to /$MEDIA/$HOSTNAME/images/`dirname $image`" - cp $image /$MEDIA/$HOSTNAME/images/`dirname $image` + # Sync remote backups. + for node in `ls /var/vservers/$NODE/var/backups/remote/`; do + mkdir -p /$MEDIA/$NODE_HOSTNAME/remote/$node + $RSYNC /var/vservers/$NODE/var/backups/remote/$node/ /$MEDIA/$NODE_HOSTNAME/remote/$node/ + done + else + # Sync local encrypted backup. + mkdir -p /$MEDIA/$HOSTNAME/duplicity + $RSYNC /var/backups/duplicity/ /$MEDIA/$HOSTNAME/duplicity/ + + # Sync remote backups. + for node in `ls /var/backups/remote/`; do + mkdir -p /$MEDIA/$HOSTNAME/remote/$node/ + $RSYNC /var/backups/remote/$node/ /$MEDIA/$HOSTNAME/remote/$node/ done + + # Copy encrypted images. + if [ -d "$IMAGES" ]; then + for image in `find $IMAGES -type f`; do + mkdir -p /$MEDIA/$HOSTNAME/images/`dirname $image` + echo "Copying image to /$MEDIA/$HOSTNAME/images/`dirname $image`" + cp $image /$MEDIA/$HOSTNAME/images/`dirname $image` + done + fi fi +} + +# Parsing. +if [ -z "$VOLUME" ]; then + echo "usage: $BASENAME <media> [nodes]" +else + shift fi + +# Sync backups for each node. +for NODE in $*; do + sync_backups_node +done diff --git a/files/sync-media b/files/sync-media index 4a99263..40ee19e 100755 --- a/files/sync-media +++ b/files/sync-media @@ -3,7 +3,8 @@ # sync-media assets using git-annex # -VOLUME="/media/usb" +DISK="$1" +VOLUME="/media/$DISK" CACHE="/var/cache/media" DOMAIN="`facter domain`" MEDIA="media.$DOMAIN" @@ -82,34 +83,36 @@ if [ -d "$CACHE" ]; then fi done - # Check storage media - MOUNT="`mount | grep $VOLUME`" - if [ ! -z "$MOUNT" ]; then - DRIVE="$(basename `echo $MOUNT | awk '{ print $1 }'`)" - fi + if [ ! -z "$DISK" ]; then + # Check storage media + MOUNT="`mount | grep $VOLUME`" + if [ ! -z "$MOUNT" ]; then + DRIVE="$(basename `echo $MOUNT | awk '{ print $1 }'`)" + fi - if [ ! -z "$DRIVE" ]; then - if [ ! -d "$VOLUME/$MEDIA" ]; then - echo "Folder $VOLUME/$MEDIA does not exist..." - else - for folder in `ls $CACHE`; do - if [ -d "$CACHE/$folder/.git/annex" ]; then - if [ ! -d "$VOLUME/$MEDIA/$folder" ]; then - ( - cd $VOLUME/$MEDIA - echo "Initializing $VOLUME/$MEDIA/$folder..." - git clone $CACHE/$folder && cd $folder && git annex init $DRIVE && \ - cd $CACHE/$folder && git remote add $DRIVE $VOLUME/$MEDIA/$folder - ) + if [ ! -z "$DRIVE" ]; then + if [ ! -d "$VOLUME/$MEDIA" ]; then + echo "Folder $VOLUME/$MEDIA does not exist..." + else + for folder in `ls $CACHE`; do + if [ -d "$CACHE/$folder/.git/annex" ]; then + if [ ! -d "$VOLUME/$MEDIA/$folder" ]; then + ( + cd $VOLUME/$MEDIA + echo "Initializing $VOLUME/$MEDIA/$folder..." + git clone $CACHE/$folder && cd $folder && git annex init $DRIVE && \ + cd $CACHE/$folder && git remote add $DRIVE $VOLUME/$MEDIA/$folder + ) + fi fi - fi - done + done + fi fi fi fi # Retrieve changes at media volumes -if [ -d "$VOLUME/$MEDIA" ]; then +if [ ! -z "$DRIVE" ] && [ -d "$VOLUME/$MEDIA" ]; then for folder in `ls $VOLUME/$MEDIA`; do if [ -d "$VOLUME/$MEDIA/$folder/.git/annex" ]; then ( |