Last active
December 14, 2015 10:18
-
-
Save oterox/5070646 to your computer and use it in GitHub Desktop.
simple python script for WP backups
It generates 3 files:
- sql dump
- theme folder backup
- wp-content folder backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import time | |
import os | |
username="db_username" | |
password="db_pass" | |
hostname="db_host" | |
filestamp=time.strftime('%Y%m%d-%H%M') | |
rootfolder="/var/www/www.pixellarylabs.com/public_html/clients/" | |
backupfolder="/var/www/www.pixellarylabs.com/backups/" | |
# wp_folder - wp_theme - wp_database | |
arr=[ | |
["btc", "btc", "btc"], | |
["tsp", "threatspace_0.7", "threatspace"], | |
["vericantdev", "purevision", "vericantdev"], | |
["decibel", "decibel_v4.0", "decibel"] | |
] | |
for row in arr: | |
filename = "%s_%s.sql" % (filestamp,row[2]) | |
os.popen("mysqldump -u %s -p%s -h %s -e --opt -c %s | gzip -c > %s%s.gz" % (username, password, hostname, row[2], backupfolder, filename)) | |
print row[2] + " - Database backup finished!" | |
os.popen("tar --exclude-caches --exclude '.git/' --exclude '*cache*' --exclude '*backup*' -czf %s%s_%s_%s_theme.tar.gz --directory %s%s/wp-content/themes/ %s" % (backupfolder, filestamp, row[0], row[1], rootfolder, row[0], row[1] )) | |
print row[0] + " - Theme backup Done!" | |
os.popen("tar --exclude-caches --exclude '.git/' --exclude '*cache*' --exclude '*backup*' -czf %s%s_%s_content.tar.gz --directory %s%s/ wp-content/" % (backupfolder, filestamp, row[0], rootfolder, row[0] )) | |
print row[0] + " - Content backup Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment