Currently Browsing: Home » Simple Snippet: Backup your Files through SSH

Simple Snippet: Backup your Files through SSH

Today we’re introducing a new type of post at Lateral Code: the simple snippet. These articles are meant to provide you with concise, meaningful snippets of code for use on your website. To kickoff off the simple snippet, we begin with an important topic for any site: backups.

Have you ever lost important files? If you have, you know the importance of keeping backups.

Files

Backups could mean the difference between life and death for your site. It’s vital to constantly generate backups and even store them on a remote machine in order to ensure full protection. All it takes is a determined attacker to possibly corrupt all of your files. As a result, this simple snippet is focused on getting you started with the backup process.

Generating backups through secure-shell (SSH) can be quite a simple task. The tar command is all you’ll need:

$ tar czvf backup.tar.gz path/to/directory

Let’s break down this snippet into it’s constituents:

tar - the command to create a tar file

c - the option that creates a tar ball
z - add gzip compression
v - verbose option to display files that are added to the tar ball
f - used to specify the archive file (in this case backup.tar.gz)

backup.tar.gz - the name of the archive file for the f option
path/to/directory - recursively search this directory for files to place in the tar ball

After running this command on the directory of your choice (generally the public or public_html directory for a full backup), you should have an archive of files which you can easily download to your own computer (or keep on your web server).

You can read more about the tar command here.

Tags:

This entry was posted on Thursday, June 24th, 2010 at 15:38:11. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Simple Snippet: Backup your Files through SSH”

  1. Vamsi says:

    Nice ..but I think this is not the best way to backup. I generally use rsync to backup all my sites .

Leave a Reply

Want to be notified when someone replies? Subscribe to this post's comment RSS feed.
Any field marked with a * is required.