Last active
June 6, 2024 10:37
-
-
Save zahidhassanshaikot/b52fccb283e654496f1c455f17f34b00 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 hidden or 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