Last active
November 30, 2021 13:58
-
-
Save mattantonelli/35056b42758fe0627a72 to your computer and use it in GitHub Desktop.
Copies backups from automysqlbackup to a remote host. Retains 1 weekly and 7 daily backups per database.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Purpose: | |
# Maintains 7 daily and 1 weekly database backups on a remote server. | |
# | |
# Configuration: | |
# Subdirectories must be created on the remote server for each database. | |
# (This includes status & fullschema directories if applicable.) | |
# | |
# Examples: | |
# | |
# Daily | |
# in: /backups/path/daily/mydb/daily_mydb_2016-02-29_03h25m_Monday.sql.gz | |
# out: daily_mydb_Monday.sql.gz | |
# | |
# Weekly | |
# in: /backups/path/weekly/mydb/weekly_mydb_2016-02-28_03h09m_8.sql.gz | |
# out: weekly_mydb.sql.gz | |
scpPath='user@host:path' | |
find '/backups/path' -type f -mmin -720 | while read file; do | |
dir=$(basename $(dirname $file)) | |
copyFile=$(basename $file | sed 's/_[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}h[0-9]\{2\}m\(_[0-9]\+\)\?//') | |
$(scp $file "$scpPath/$dir/$copyFile") | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From what I can see, you now just need to specify a script in the POSTBACKUP line in /etc/default/automysqlbackup for copying/transferring the generated backups off-server.