sunetdrive/templates/script/backupmultinodedb.erb.sh

23 lines
1.1 KiB
Bash
Raw Permalink Normal View History

2023-03-13 15:20:03 +00:00
#!/bin/bash
# Backup all databases
# We sleep a deterministic amount of time, which will be between 0 an 128 m and allways the same within
# a specific host, but will differ between hosts
sleep $((16#$(ip a | grep "link/ether" | head -1 | awk -F ':' '{print $6}' | awk '{print $1}') / 2))m
number_of_full_to_keep=7
2023-03-13 15:23:51 +00:00
backup="multinode-db1.$(hostname -d)"
2023-03-13 15:20:03 +00:00
remote_backup_dir="/etc/mariadb/backups"
backup_dir="/opt/backups"
bucket="db-backups-multinode"
mirror="common-<%= @environment %>-mirror"
echo "Backing up all databases for for multinode customer"
ssh "${backup}" "sudo /home/script/bin/backup_multinode_db.sh"
echo "Copying backups here"
mkdir -p ${backup_dir}
2023-03-13 15:27:32 +00:00
scp "script@${backup}:${remote_backup_dir}/mariadb-dump*.sql.gz" "${backup_dir}"
2023-03-13 15:20:03 +00:00
echo "Copying backups to remote bucket"
rclone mkdir "${mirror}:${bucket}"
duplicity --full-if-older-than 1M --tempdir /mnt --archive-dir /mnt --no-encryption "${backup_dir}" "rclone://${mirror}:/${bucket}"
duplicity remove-all-but-n-full "${number_of_full_to_keep}" --tempdir /mnt --archive-dir /mnt --force "rclone://${mirror}:/${bucket}"
echo "cleaning up"
rm -r "${backup_dir}"