Created
December 29, 2021 11:12
-
-
Save Robiussani152/142fe0bde09876eec93b9a3bec4650b9 to your computer and use it in GitHub Desktop.
bash file for db backup and if the backup file is older than 1 day it will automatically delete those files.
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
#!/bin/bash | |
#your database info | |
DBHOST='localhost' | |
DBUSER='db_user' | |
DBPW='db_password' | |
DBNAME=('db_name') | |
#get recent version of databases from array | |
for i in "${DBNAME[@]}" | |
do | |
mysqldump --opt --user=$DBUSER --password=$DBPW --host=$DBHOST --no-tablespaces $i --lock-tables=false > /var/www/backups/$i.`date +\%Y-\%m-\%d_\%H-\%M-\%S`.sql | |
done | |
#remove db files older than 1 day (for 30 min: -mmin +30) | |
find /var/www/backups/*.sql -type f -daystart -mtime +0 -exec rm {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment