diff --git a/templates/script/backupdb.erb.sh b/templates/script/backupdb.erb.sh index 1eb7992..c83abac 100644 --- a/templates/script/backupdb.erb.sh +++ b/templates/script/backupdb.erb.sh @@ -14,8 +14,6 @@ if ! [[ ${backup} =~ backup1.*sunet.se$ ]]; then echo "Example: ${0} backup1.sunet.drive.sunet.se" fi backup_dir="/opt/backups" -backup_dir_long="${backup_dir}/backups" -mkdir -p ${backup_dir} bucket="db-backups" mirror="<%= @customer %>-<%= @environment %>-mirror" if [[ ${mirror} =~ common-(test|prod)-mirror ]]; then @@ -23,12 +21,13 @@ if [[ ${mirror} =~ common-(test|prod)-mirror ]]; then bucket="${bucket}-${suffix}" backup_dir="${backup_dir}-${suffix}" fi +mkdir -p ${backup_dir} echo "Backing up database for ${backup}" ssh ${backup} "sudo /home/script/bin/backup_db.sh" echo "Cleaning up old backups for ${backup}" ssh ${backup} "sudo /home/script/bin/purge_backups.sh /opt/mariadb_backup/backups/" echo "Copying backups here" -scp script@${backup}:/opt/mariadb_backup/backups/$(date +%Y/%m/%d)/*.gz ${backup_dir_long} +scp script@${backup}:/opt/mariadb_backup/backups/$(date +%Y/%m/%d)/*.gz ${backup_dir} 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}