Automate WordPress backup with Python / Fabric

Python’s Fabric module makes automation easy.  This post shows how to use a Fabric script to backup a WordPress installation, but could be used for most LAMP backup situations!

Goals of this Post:

  • backup SQL to /tmp
  • backup WEB ROOT to /tmp
  • tar SQL + site & zip
  • download
  • delete /tmp

The Fabric script is written for to be executed as a ‘sudo’ user.  If you want to perform the actions in the script as root or another user,  replace ‘sudo()’ with ‘run()’.

For help installing Fabric look at my previous post:

For more information on Fabric:


[matt@mattcom1 wpbackup]$ fab backup_all
[] Executing task ‘backup_all’
[] sudo: mysqldump -u savelonoadmin -p45482lonoF#m! –database savelono > savelono-$(date +%m-%d-%Y).sql
[] out: sudo password:
[] out:
[] sudo: cp -rfp /var/www/html savelono-site-$(date +%m-%d-%Y)
[] out: sudo password:
[] out:
[] sudo: tar -czvf savelono-site-$(date +%m-%d-%Y).tar.gz savelono-*
[] out: sudo password:
[] out: savelono-09-11-2017.sql
[] out: savelono-site-09-11-2017/
[] out: savelono-site-09-11-2017/readme.9d9380967341b4551da5eb9ee499

[] out: savelono-site-09-11-2017/json2.js
[] out: savelono-site-09-11-2017/wp-login.php
[] out: savelono-site-09-11-2017/images
[] out:

[] download: /home/matt/backup/savelono-site-backups/ <- /tmp/savelono-site-09-11-2017.tar.gz
[] sudo: rm -rf /tmp/savelono*
[] out: sudo password:
[] out:

Disconnecting from… done.

And that’s it!  Easy Python syntax for issuing remote and local shell commands through SSH.  Thank you for reading!  I hope you find this useful.


No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment