#!/bin/bash ## example host config # set_vars root karif # # run_ssh $src /root/backup.pl start # # run_ssh backup@$host "cd /home/backup/mysql-dumps; /home/backup/create-mysql-dumps" # run_ssh backup@$host "cd /home/backup/psql-dumps; /home/backup/create-psql-dumps" # backup_rsync "$src:/home/backup/mysql-dumps/" "$dst/mysql-dumps/" # backup_rsync "$src:/home/backup/psql-dumps/" "$dst/psql-dumps/" # run_ssh backup@$host "rm -f /home/backup/mysql-dumps/*.sql.gz" # run_ssh backup@$host "rm -f /home/backup/psql-dumps/*.dump" # # backup_rsync --filter=". /mnt/backup/filters/karif_root_filter" "$src:/mnt/snapshots/vg0-root/" "$dst/root/" # backup_rsync --filter=". /mnt/backup/filters/karif_home_filter" "$src:/mnt/snapshots/vg0-home/" "$dst/home/" # backup_rsync "$src:/boot/" "$dst/boot/" # # run_ssh $src /root/backup.sh stop # # create_and_clean_snapshots "$dst_fs" set -e backup_rsync() { local dir="${@: -1}" mkdir -p "$dir" rsync --rsh="/usr/bin/ssh -i /root/.ssh/id_rsa-backup" --delete --numeric-ids --delete-excluded --max-delete=100000 -axEAXHv "$@" } run_ssh() { ssh -i /root/.ssh/id_rsa-backup "$@" } set_vars() { user="$1" host="$2" src="$user@$host" dst_fs="$backup_fs_base/$host" dst="$(zfs get mountpoint -o value -H "$dst_fs")" } create_snapshots() { local dst_fs=$1 if [[ "$(date +%d)" = "01" ]]; then /root/zfs_create_dated_snapshot.sh "$dst_fs" monthly fi if [[ "$(date +%u)" = "7" ]]; then /root/zfs_create_dated_snapshot.sh "$dst_fs" weekly fi /root/zfs_create_dated_snapshot.sh "$dst_fs" daily } clean_snapshots() { local dst_fs=$1 /root/zfs_snapshot_cleanup.sh "$dst_fs" daily 10 /root/zfs_snapshot_cleanup.sh "$dst_fs" weekly 4 /root/zfs_snapshot_cleanup.sh "$dst_fs" monthly 3 } create_and_clean_snapshots() { local dst_fs=$1 create_snapshots "$dst_fs" clean_snapshots "$dst_fs" } backup_fs_base="data/backup_zfs/backups" if (($#<1)); then echo "usage: ${0##*/} " exit 1 fi source "${0%/*}/host-configs/$1"