Automatically Backup MySQL database on linux server

前端 未结 7 669
無奈伤痛
無奈伤痛 2021-02-04 10:32

I need a script that automatically makes a backup of a MySql Database. I know there are a lot of posts and scripts out there on this topic already but here is where mine differs

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 11:27

    You can do most of this with a one-line cronjob set to run every 30 minutes:

    mysqldump -u -p  > /path/to/dumps/db.$(date +%a.%H:%M).dump
    

    This will create a database dump every 30 minutes, and every week it'll start overwriting the previous week's dumps.

    Then have another cronjob that runs once a week that copies the most recent dump to a separate location where you're keeping snapshots.

提交回复
热议问题