Backup the MySQL databases of all your hosted websites to your computer by using an SSH connection to the webserver.
-
Make sure you have
pip
&python
installed -
Install the paramiko package
sudo pip install paramiko
-
Download or git clone the source files
-
Make sure that you can access your webserver by using SSH. You’ll need to make an SSH key.
-
Copy the result of
cat ~/.ssh/id_rsa.pub
-
SSH to your server
-
vim ~/.ssh/authorized_keys
-
Paste the contents (your key) and save
-
ctrl+d to exit
-
Open the
config/config.json.dist
and rename it toconfig/config.json
and fill the details of your webserver and database credentials. You can add as many webservers/databases as you want!{ "settings": { "backup_folder": "backup/" /* The local backup folder */ }, "websites": { "name_firstwebsite": { "config": { "host": "", /* Webserver hostname */ "username": "" /* Webserver username */ }, "databases": { "database_examplename1": { "mysql_host": "", /* Mysql hostname */ "mysql_user": "", /* Mysql username */ "mysql_pwd": "" /* Mysql password */ } } }, "name_secondwebsite": { ... } } }
-
Run
python backup-mysql-database-ssh.py
to backup your database or configure it to run periodically as a cronjob (OS X tip: Lingon). Using Lingon, create a new task, give it a name and let it execute/usr/bin/python /Users/pathtoscript/backup-mysql-database-ssh.py
at e.g. every 12 hours.
If you encounter any bugs, please create an issue and I’ll try to fix it (or feel free to fix it yourself with a pull-request).
- Twitter: @jessedobbelaere
- E-mail: jesse@dobbelaere-ae.be for any questions or remarks.