You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

#!/usr/bin/env bash
lockfile="/tmp/stupidbackup.lock"
exec 9>"$lockfile"
if ! flock -n 9
then printf 'Only one running instance is allowed.\n';
exit 1
fi
destination="/mnt/bigstorage/"
dontcare="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=ERROR"
now=`date +"%Y-%m-%d"`
path_script="$(realpath "${BASH_SOURCE[-1]}")"
path_dir="$(dirname "$path_script")"
for domain in "login.wownero.com" "wownero.com" "git.wownero.com"; do
host="root@$domain"
tmpd=`ssh $dontcare "$host" "mktemp -d -t wow-XXXXXXXXXX"`
if [ -z "$tmpd" ]
then
echo "[$domain] failed to create tmp directory"
continue
fi
echo "[$domain] created $tmpd"
scp $dontcare -rP22 "$path_dir/backup.sh" "$host:$tmpd/backup.sh"
echo "[$domain] uploaded backup script"
ssh $dontcare "$host" "cd $tmpd; bash $tmpd/backup.sh"
echo "[$domain] executed backup script"
scp $dontcare -rP22 "$host:$tmpd" "$destination/$now-$domain"
echo "[$domain] downloaded backups"
ssh $dontcare "$host" "rm -rf $tmpd"
echo "[$domain] finished"
done
rm "$lockfile"
# delete old files
find $destination -type f -mtime +40 -delete
find $destination -type d -empty -delete