Tag:MySQL backup script is reserved for 7 days

  • MySQL backup script and keep it for 7 days


    Script requirements: Backup MySQL database every day and keep the script for 7 days. Stored in the / opt / dbbak directory. The script name is database_ xxxx-xx- xx.sql Script content: #!/bin/bash export NOW=”$(date +”%Y-%m-%d”)” export DATA_DIR=/opt/dbbak /usr/local/ywgh/mysql/bin/mysqldump –opt -uroot –p ‘mypassword’ ywghblog > $DATA_DIR/ywghblog/ywghblog_$NOW.sql find $DATA_DIR/ywghblog -type f -name “*.sql” -mtime +7 -exec rm […]