Tuesday, January 24, 2023

backing up mysql databases to google shared drive

Following the unixcraft script, also seen on github, implemented a weekly backup for some of our mysql databases. 

# 05 0 * * Sun /path/to/script.sh

as root.  

Edit: The reason for the issue below was different. Explained in a separate post here

When I added an rclone move line after the backup line to the script, it was moving incomplete 20 kB files to the shared google drive. So, am running the rclone move as a separate script after half an hour,

 # 35 0 * * Sun /path/to/script.sh

which has lines similar to

MBD="$DEST/mysql"
rclone --config "/home/ouruser/.config/rclone/rclone.conf" move $MBD/ gshareddrive:/

The database dump takes only a couple of minutes, so the half an hour gap is more than sufficient. 

 Some things to remember about using this script:

  • If we're defining only a few databases to be backed up, like
    # Store list of databases
    DBS="db1 db2"

    then we need to disable/comment out the DBS= line which appears later,
    #DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"

  • As seen above, the list of databases (or those to be ignored, in the IGGY variable) are to be entered separated by spaces.

  • The script changes the directory permissions for security, so it is meant to be run as root. Otherwise, we will find that it could not write the files (if run as an unprivileged user).

  • Edit: Have to provide hard-coded full path to MYSQLDUMP - see this post.


No comments:

Post a Comment