mirror of
https://github.com/fradelg/docker-mysql-cron-backup.git
synced 2025-01-18 16:22:33 +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
|
then
|
||||||
echo "Dumping database: $db"
|
echo "Dumping database: $db"
|
||||||
FILENAME=/backup/$DATE.$db.sql
|
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"
|
if mysqldump -h "$MYSQL_HOST" -P "$MYSQL_PORT" -u "$MYSQL_USER" -p"$MYSQL_PASS" --databases "$db" $MYSQLDUMP_OPTS > "$FILENAME"
|
||||||
then
|
then
|
||||||
gzip -f "$FILENAME"
|
gzip -f "$FILENAME"
|
||||||
|
rm "$LATEST"
|
||||||
|
ln -s "$FILENAME" "$LATEST"
|
||||||
else
|
else
|
||||||
rm -rf "$FILENAME"
|
rm -rf "$FILENAME"
|
||||||
fi
|
fi
|
||||||
|
@ -22,9 +25,9 @@ done
|
||||||
|
|
||||||
if [ -n "$MAX_BACKUPS" ]
|
if [ -n "$MAX_BACKUPS" ]
|
||||||
then
|
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
|
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"
|
echo "Backup $TARGET is deleted"
|
||||||
rm -rf "$TARGET"
|
rm -rf "$TARGET"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue