mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2024-11-01 08:31:45 +01:00
Create a link to the latest backup
The symlink is not considered a backup itself and never deleted according to the backup quota
This commit is contained in:
parent
4c71297f03
commit
bcc8f68f72
1 changed files with 5 additions and 2 deletions
|
@ -11,9 +11,12 @@ do
|
|||
then
|
||||
echo "Dumping database: $db"
|
||||
FILENAME=/backup/$DATE.$db.sql
|
||||
LATEST=/backup/latest.$db.sql.gz
|
||||
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME"
|
||||
then
|
||||
gzip -f "$FILENAME"
|
||||
rm "$LATEST"
|
||||
ln -s "$FILENAME" "$LATEST"
|
||||
else
|
||||
rm -rf "$FILENAME"
|
||||
fi
|
||||
|
@ -22,9 +25,9 @@ done
|
|||
|
||||
if [ -n "$MAX_BACKUPS" ]
|
||||
then
|
||||
while [ "$(find /backup -maxdepth 1 -name "*.sql.gz" | wc -l)" -gt "$MAX_BACKUPS" ]
|
||||
while [ "$(find /backup -maxdepth 1 -name "*.sql.gz" -type f | wc -l)" -gt "$MAX_BACKUPS" ]
|
||||
do
|
||||
TARGET=$(find /backup -maxdepth 1 -name "*.sql.gz" | sort | head -n 1)
|
||||
TARGET=$(find /backup -maxdepth 1 -name "*.sql.gz" -type f | sort | head -n 1)
|
||||
echo "Backup $TARGET is deleted"
|
||||
rm -rf "$TARGET"
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue