Skip to content

Instantly share code, notes, and snippets.

@marcqualie
Last active April 20, 2016 14:25
Show Gist options
  • Save marcqualie/6099324 to your computer and use it in GitHub Desktop.
Save marcqualie/6099324 to your computer and use it in GitHub Desktop.
Simple scripts to backup MySQL and Web Content
#!/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"
#!/bin/sh
~/backup/mysql
~/backup/www
~/backup/s3
#!/bin/sh
s3cmd sync /backup/ s3://yourbucket/`hostname`/
#!/bin/sh
tar -czvf /backup/www/`date +%Y%m%d`.tar.gz /var/www
#!/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