Last active
April 20, 2016 14:25
-
-
Save marcqualie/6099324 to your computer and use it in GitHub Desktop.
Simple scripts to backup MySQL and Web Content
This file contains hidden or 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/env python | |
import os | |
import time | |
# Variables | |
username = 'backup' | |
password = 'password' | |
hostname = 'localhost' | |
filestamp = time.strftime('%Y%m%d') | |
# Save all | |
database_list_command = "mysql -u%s -p%s -h%s --silent -N -e 'show databases'" % (username, password, hostname) | |
for database in os.popen(database_list_command).readlines(): | |
database = database.strip() | |
if database == 'information_schema' or database == 'performance_schema' or database == 'mysql': | |
continue | |
filename = "/backup/mysql/%s-%s.sql" % (database, filestamp) | |
print "Backing up %s" % filename | |
os.popen("mysqldump -u%s -p%s -h%s -e --opt -c %s | gzip -c -9 > %s.gz" % (username, password, hostname, database, filename)) | |
print ".. done" |
This file contains hidden or 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
#!/bin/sh | |
~/backup/mysql | |
~/backup/www | |
~/backup/s3 |
This file contains hidden or 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
#!/bin/sh | |
s3cmd sync /backup/ s3://yourbucket/`hostname`/ |
This file contains hidden or 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
#!/bin/sh | |
tar -czvf /backup/www/`date +%Y%m%d`.tar.gz /var/www |
This file contains hidden or 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
#!/bin/sh | |
wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add - | |
wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list | |
apt-get update | |
apt-get install -y s3cmd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment