From fdb07b542860089eb208ec5967826a2225899d10 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sun, 2 Oct 2016 15:31:42 -0300 Subject: Adds media and backup scripts originally from puppet-backup --- share/hydractl/sync-backups | 74 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 share/hydractl/sync-backups (limited to 'share/hydractl/sync-backups') diff --git a/share/hydractl/sync-backups b/share/hydractl/sync-backups new file mode 100755 index 0000000..aa92754 --- /dev/null +++ b/share/hydractl/sync-backups @@ -0,0 +1,74 @@ +#!/bin/bash +# +# sync a removable volume with system backups. +# + +# Parameters. +BASENAME="`basename $0`" +VOLUME="$1" +MEDIA="/media/$VOLUME" +BWLIMIT=${BWLIMIT:=32000} +IMAGES="/var/data/crypt/" +RSYNC="ionice -c 3 nice -n 19 rsync -avH --delete --bwlimit=$BWLIMIT" +CP="ionice -c 3 nice -n 19 cp" + +# 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. + echo "Syncing /var/vservers/$NODE/var/backups/duplicity/..." + 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 + echo "Syncing /var/vservers/$NODE/var/backups/remote/$node/..." + 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. + echo "Syncing /var/backups/duplicity/..." + mkdir -p /$MEDIA/$HOSTNAME/duplicity + $RSYNC /var/backups/duplicity/ /$MEDIA/$HOSTNAME/duplicity/ + + # Sync remote backups. + for node in `ls /var/backups/remote/`; do + echo "Syncing /var/backups/remote/$node/..." + 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 -name '*.img' -type f`; do + echo "Copying image to /$MEDIA/$HOSTNAME/images/`dirname $image`" + mkdir -p /$MEDIA/$HOSTNAME/images/`dirname $image` + $CP $image /$MEDIA/$HOSTNAME/images/`dirname $image` + done + fi + fi +} + +# Parsing. +if [ -z "$VOLUME" ]; then + echo "usage: $BASENAME [nodes]" + exit 1 +else + shift +fi + +# Sync backups for each node. +if [ ! -z "$*" ]; then + for NODE in $*; do + sync_backups_node + done +else + sync_backups_node +fi -- cgit v1.2.3