Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to realize mysql data backup and cleaning through shell script

Shulou Source: shulou.com Published: 2022-06-01 01:19:07 09月28日 Update

This article introduces the relevant knowledge of "how to achieve mysql data backup and cleaning through shell scripts". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The shell script on SCRIPTubuntu realizes the scheduled backup of the database and the deletion of data from a month ago.

Curdate= `date +% Ymuri% mcombe% dwells% Hmura% M`date "/ opt/backup/db" databasename= "DBName" username= "root" password= "- skip-password" # if password isn't empty use "- pxxxxx" # the number of days to keepbackups keepbackups= `date-d'30 days ago' +% Yashi% d`date = echo Start backup MySQL DB mysqldump-u$ {username} ${password} ${databasename} > ${backupdir} / ${databasename} _ {curdate} .sql echo Done. Echo Deleting old backups cd $backupdir find. -name "${databasename} _ ${keepbackups} *" | xargs rm-rf echo Done. Echo = "how to backup and clean up mysql data through shell scripts" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Data backup script data backup content more knowledge practicality achievement next dilemma reality situation database article case editing website industry process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple OPPO Reno NVidia Docker