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:
Manuel 2018-11-08 11:15:00 +01:00 committed by GitHub
parent 4c71297f03
commit bcc8f68f72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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