WebFaction
Community site: login faq
0
1

Is there an "easy" way to backup all my databases and webapps? Or do I have to dump all databases and then copy all directories one by one?

asked 20 Jul '11, 05:22

ampelmann
3532024
accept rate: 0%


Hi,

There is no easier way to do this. Perhaps you could speed it up a little by running the following command from your home directory:

tar zcvf webapps.tar.gz webapps/

and then downloading the webapps.tar.gz file.

You can also check our online documentation on dumping database data.

permanent link

answered 20 Jul '11, 06:34

todork
1.2k5
accept rate: 34%

Know it's an old question but this is one of the places I was searching for info before I decided to roll my own python script to accomplish this, through git and bitbucket.

My method accomplishes the following:

  1. Creates dumps of mysql databases
  2. Creates dumps of svn repositories
  3. Pushes sql and svn dumps + the webapps directory to bitbucket via git
  4. Runs daily through cron

You will need to create an empty repo on bitbucket, and push the contents of your home directory to it (be sure to add the libs folder and other stuff specific for what you have to your .gitignore). Set up SSH keys as well of course. Svn dumps are taken on any webapp with "svn" in the name. I am including the python script as well as some gitignore and cron entries you may need.

EDIT: I may write a more detailed explanation of how to set this up if I feel there is an audience for it.

Caution: Necessary security precautions are your own responsibility (I set file permissions to 700 on the python script, I'm no expert but I assume this is safe?)


Backup.py (~/bin/backup.py)

#!/usr/bin/python
import MySQLdb
import os

def niceRun(cmd):
        os.system("ionice -c2 -n6 " + cmd)

#########################
#      SETTINGS         #
#########################
sqlBackupDir = "~/mysql-backup"
svnBackupDir = "~/svn-backup"

# databases
dbprefix = "XXXXXX_" # MODIFY THIS - YOUR SERVER USERNAME + "_" IS YOUR DB PREFIX
dblist = {"db1":"some_pass", # MODIFY THESE LINES WITH: "dbname":"password"
        "wordpress":"lala123",
        "anothersite":"dskjuew"
        }

#########################
#     MYSQL DUMPS       #
#########################
# delete old mysql dumps
niceRun("rm -r "+ sqlBackupDir)
niceRun("mkdir "+ sqlBackupDir)
# create new mysql dumps
for db in dblist:
        pw = dblist[db]
        dbname = dbprefix + db
        backupfile = sqlBackupDir + "/" + dbname + ".sql.gz"
        niceRun("echo 'Backing up " + dbname + " database'")
        niceRun("mysqldump --skip-dump-date -u " + dbname + " -h localhost -p" + pw + " --all-databases > " + backupfile)

#########################
#       SVN DUMPS       #
#########################
# delete old svn dumps
niceRun("rm -r " + svnBackupDir)
niceRun("mkdir " + svnBackupDir)
# create new dumps
for dir in os.listdir(os.path.abspath("webapps")):
        if "svn" in dir:
                niceRun("svnadmin dump ~/webapps/" + dir + " > " + svnBackupDir + "/" + dir + ".dmp")

#########################
#         GIT           #
#########################
# git add, commit, push
niceRun("git pull")
niceRun("git add .")
niceRun("git commit -m 'Backup.py automatic backup'")
niceRun("git push")

# done
niceRun("echo 'Backup complete'")

Cron

You can add the script to your cronjobs like so, this example will run at 2:40 every night. (replace XXXX with your username):

40      2       *       *       *       /usr/local/bin/python2.7 /home/XXXX/bin/backup.py

Gitignore (~/.gitignore)

Just for reference, here is the section of my .gitignore which is for webfaction specific stuff:

# webfaction stuff   #
######################
/bin/.ph
/lib/
/logs/
permanent link

answered 01 Feb '13, 13:22

Madsn
4314
accept rate: 0%

edited 13 Feb '13, 09:48

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×36

question asked: 20 Jul '11, 05:22

question was seen: 10,417 times

last updated: 13 Feb '13, 09:48

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM