aboutsummaryrefslogtreecommitdiff
path: root/files/sync-backups
blob: c23e05dd6a15278916ac8def8e310b35a9b9d5b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# sync a removable volume with system backups.
#

NODE="$1"
MEDIA="/media/usb"
BWLIMIT="2500"
IMAGES="/var/data/crypt/"
RSYNC="nice -n 19 rsync -avH --delete --bwlimit=$BWLIMIT"

if [ ! -z "$NODE" ]; then
  for node in `ls /var/vservers/$NODE/var/backups/remote/`; do
    mkdir -p /$MEDIA/$NODE/remote/$node
    $RSYNC /var/vservers/$NODE/var/backups/remote/$node/ /$MEDIA/$NODE/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/$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