Linux shell script for database backup

后端 未结 10 1750
忘了有多久
忘了有多久 2020-12-02 04:59

I tried many scripts for database backup but I couldn\'t make it. I want to backup my database every hour.
I added files to \"/etc/cron.hourly/\" folder, changed its chm

10条回答
  •  星月不相逢
    2020-12-02 05:43

    Create a script similar to this:

    #!/bin/sh -e
    
    location=~/`date +%Y%m%d_%H%M%S`.db
    
    mysqldump -u root --password= database_name > $location
    
    gzip $location
    

    Then you can edit the crontab of the user that the script is going to run as:

    $> crontab -e
    

    And append the entry

    01 * * * * ~/script_path.sh
    

    This will make it run on the first minute of every hour every day.

    Then you just have to add in your rolls and other functionality and you are good to go.

提交回复
热议问题