Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Last week I started making daily backups of my relatively small (~300mb) site. The backups are zipped, so it's less space, but it will quickly add up, especially as my site gets bigger.

I was thinking of unzipping the latest backup, and from now on just using mercurial to add/update files from newer backups.

Are there any drawbacks to this? Is there a better way to do it?

share|improve this question
Why not just put the site itself in version control? Then backup the repo? – CamelBlues May 15 '12 at 20:42
up vote 8 down vote accepted

Git is your best choice, since it allows "cheap" commits, branches, etc. every commit is simply a diff of the previous commit, so the size is minimal, for example if you have


and you only change index.html, then that is all that is stored in the commit, making git extremely space efficient, whats more, it only stores the one or two lines you changed, it could be 500000 line html file (WoAH) making it super fast.

This does mean that the first push to whatever git server that you're using might be long. But everything after that should take no time at all.

And the beautiful thing is, everything can be done locally, you can do as many changes as you want to a local repository, commit as many times as you want, and then push all at once, and since repositories can be local, you can push to just another physical (in the virtual sense :P) on your hard drive, or to a webserver, or through email even!

share|improve this answer

I use git for this purpose. Assuming unix/linux:

cd /path/to/site
git init
chmod 600 .git
vi .gitignore  # add any tmp files you dont want here
git add .
git commit -m "initial commit"

Then, add this to the nightly crontab:

0 3 * * *     cd /path/to/project; git add . && git add -u && git commit -m "Daily Commit" 

You could also setup a push to a remote (like github) for true backups.

share|improve this answer
Thanks! Also, what about the sql database? Can I backup that up automatically somehow? And what about the password? – mowwwalker May 15 '12 at 21:22

IMO this is the best way, I'm doing it like this as well.
(just commit every change and push the whole thing to a private repository on Bitbucket)

It makes absolutely no sense to always copy the whole 300 MB if only a few files have changed.
Plus, you get a changelog "for free" (which you don't have if you just make a ZIP file every day).

share|improve this answer

Definitely the way to go here. One additional plus -- you can easily revert changes in many cases if need be. Saved me from more than a few bad updates . . .

share|improve this answer

Git is a great way to go as others' mentioned. For database (like MySQL), you should be able to create a cron job that runs a script to backup the database and to rotate the the log files.

s, and use daily logging I do something like:

/usr/sbin/logrotate -s status-file logrotate.conf

mysqldump --tables --add_drop_table --user=my-db-username --password='my-password' --host=dbase-server my-database > /the/backup/dir/my-database.sql

My logrotate.conf says to do daily logs, compress, rotate every 14 day. I wildcard it to apply to all *.sql files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.