Google Drive MySQL Dumper
Small script which exports a MySQL database to a file and uploads it to Google Drive.
By default, the script works on a 14 day retention policy. That is, local and remote backups are kept for up to 14 days, any local backup files the script finds in the backup directory will be gzipped before the newest backup is exported and uploaded.
Requires the gdrive command line utility for Google Drive.
Download the gdrive utility from its GitHub page and follow its installation guide.
Clone this repository
db-dump.shscript executable, and link it somewhere it can be called from any directory e.g:
$ chmod +x /path/to/db-dump.sh $ sudo ln -s /path/to/db-dump.sh /usr/local/bin/db-dump
Set up your
db-dump.conffile, either manually by copying
db-dump.conf.dist, or by typing
db-dump configat the command line:
$ db-dump config Generating config file... Enter Database Name: mydatabase Enter Google Drive Folder ID: abc123def456 Config file generated.
Run the script
$ db-dump Uploading /var/spool/db-dump/mydatabase-2016-11-09_17:09:51.sql Uploaded 0BwvPrE-VPdlkb7BhLGVJZUxST1z at 356.8 KB/s, total 683.5 KB Done
The following options must be set and do not have default values:
|db_name||Name of the database to export|
|gdrive_folder_id||Google Drive folder ID where files get uploaded|
The following options do have default values and can be tweaked as desired:
|date_format||Date format for dates appended to export files||
|dump_dir||The local directory where export files will be stored||
|retention_days||The number of days to retain export files||
|mysql_opts||Options to pass to
Options can be changed in the main
db-dump.conf file or can be overridden on a per user basis by creating
a config file within your home directory:
Options can also be changed by passing a config file as the first argument to the script. This allows the script to be used with different databases and configurations:
The easiest way to automatically run the script over a given interval is to link it into one of the
/etc/cron.* directories, e.g:
sudo ln -s /path/to/db-dump.sh /etc/cron.daily/db-dump
The above command will cause the script to be run once every 24 hours.
Released under the MIT license