How To Backup Your Website Through SSH Command Line
|
| ||||||||
| Compare: | Web Design Calculator | Web Design Cost Guidelines |
Are you an E-Commerce Web Designer? Add a Free Listing
Backing up your website or blog can be an expensive and arduous task, requiring a variety of plugins, or additional plans from your hosting provider – but it needn’t be really. If you have SSH access to your website host (generally you would need at least a virtual private server for this), then it’s easy to backup, restore and migrate your entire website with only a few commands. Let me show you how.
What is SSH Command Line?
SSH gives you the ability to talk directly to your web-server. It doesn’t give a pretty interface, or a nice GUI, just a straight-up powerful command line. This can be daunting to some people, but the sheer power, speed, and level of automation it provides can be an absolute life-saver and makes the process of migrating sites incredibly easy.
Most shared hosts unfortunately don’t allow SSH access to your account, at least not by default. If you’re hosting with GoDaddy, you can enable it though, so be sure to check first.
To log in via SSH, open up the Terminal in OS X (or get some free SSH software for Windows) and type in the following:
ssh username@yourdomain.com
You’ll be prompted for your password. If you’ve never used SSH before, you might be surprised when typing in your password doesn’t anything on screen. Don’t worry, that’s for security.
Once logged in, you’ll be presented with a command prompt, similar to the following:
-bash-3.2$
This means everything is fine, so go ahead and continue with these commands.
Start by taking a look around and trying to navigate to your web directory. Type:
ls
To ‘list’ the current files and folders.
cd directoryname
to change to a directory. In this case, I’m going to navigate to the httpdocs directory, which is the root of my web site (where all my Wordpress files are stored). You can then ‘ls’ again, just to be sure.

At this point, we’re ready to begin the SSH backup process.
Backing up the Database:
Since the majority readers will be doing this with a WordPress install, you will most certainly have a database to backup in addition to any files stored on the site. First off, you’ll need 3 bits of information to backup your database, but all can be found within wp-config.php (if you’re running wordpress, that is):
- Database name
- Database user
- Database password
Then, issue this simple command, being sure to replace the username, table name, and backup filename where neccessary:
mysqldump --add-drop-table -u username -p tablename > backupfilename.sql
Hit enter, and enter your password. Once it’s run, you can then issue another ‘ls’ command to check that the file has been output. Congratulations, this is all the information in your database as a single SQL file, ready to backup or import somewhere else.
Note: I’ve assumed that your database server is running on the same server on which you are hosting. On a GoDaddy host however, the MySQL database is actually stored remotely on a separate server to which you don’t have SSH access. In cases like these, you will need to access PHPMyAdmin via the hosting control panel, but that is out of the scope of this tutorial.
Backing Up Files:
Now that we have the database stored to single file on the server, we can go ahead and backup both that and your website files down to a single compressed backup file. To do this, we are going to issue one simple command. You need only replace yourbackupfilename with whatever you want it to be called.
tar -vcf yourbackupfilename.tar .
Let me break that down. Tar is a common Linux compression format, similar to zip but more efficient. -vcf are simple some options that say “make a new archive, and tell me what you’re doing”. Next is the name of the file we want to create, and finally a single period mark tells it to include everything. We could have written * instead, but this would miss any hidden files such .htaccess which is essential for WordPress.
That’s it. Once that’s run, you will have a single .tar file consisting of every file on your site. You could log in via FTP at this point and download it, but let me show one final step that allows you to restore all these files.
Restoring Everything:
Let’s say the worst has happened, and something has gone horribly wrong with your site. You’ve got a tar file of everything that you backed up last week, so now you’d like to restore it to that. First off, log in via FTP and upload the backup file onto your server. Perhaps you’ve been storing them in a special directory. Either way, move the latest complete backup file into the root of your site, and we’ll begin.
Start by unpacking all the files, the reverse of what we did to back them up:
tar -vxf yourbackupfilename.tar
The crucial difference here is in the -vxf switch, which tells it to extract the files instead of creating a new backup. Also, there is no period on the end of the command this time.
The last step is to suck your database back in to where it was before. Make sure you have a blank database setup with the same password and tablename as before, or you’ll need to change your site configuration settings too. To suck the data back in, issue this command:
mysql -u username -p tablename > databasebackupfilename.sql
Next week: Automating Your Backups
That’s enough to get you started with doing SSH backups for now, then next I’ll show how to automate the task with a simple shell script and a CRON command. If you have some Amazon s3 storage space, I’ll even show you how you can automatically upload your backup files to a storage bucket once they’re done.
One last tip – when I first began to use the command line, this one really impressed me – try pressing the tab key when your typing in a long filename, and if the name is unique enough it will attempt to autocomplete the rest of the filename!
Need Assistance? Ask questions to MakeUseOf staff and thousands of other readers on MakeUseOf Answers!
More articles about: backup, blogging tips, blogging tools, command line, commands, restore, wordpress
Sun, 10 Apr 2011 17:30:15 GMT
Tags: backup, blogging tips, blogging tools, command line, commands, How-To Articles, restore, wordpress,
Port Arthur E-Commerce | Wilmington E-Commerce | Des Plaines E-Commerce | Appleton E-Commerce | Dumyat E-Commerce | Williamsburg E-Commerce | Haddon Heights E-Commerce | Galena E-Commerce | Camden E-Commerce | Ahmadabad E-Commerce |
backup
How To Easily Synchronize Folders Outside Dropbox Using Symlinks
There’s a long running discussion on Quora that grabbed my attention. The topic is about the reason why Dropbox is more popular than other free programs with similar functionality. The various answers boiled down to this: simplicity. You put your fi
4 Great Uses For Amazon’s S3 Web Services
Despite Amazon being most well known for their retail services, they actually offer a host of web services for developers and home users that take advantage of Amazons experience and scalability with massive amounts of
blogging tips
10 More Websites That Help Cure Writer’s Block With Writing Prompts
Did famous authors like Mark Twain and Leo Tolstoy suffer from writer’s block? You can bet your last drop of ink that they did. Just type “writer’s block and famous authors” in Google and see the results that get splashed across the screen. In
How To Add Rich Snippets for Reviews To Your WordPress Blog
I wrote a few weeks ago about how Google was changing search results dramatically by including more and more semantic information – or what Google likes to refer to as Rich Snippets. Most recently, this was in the form of recipe meta-data, such as i
People Love You. Show It Off On WordPress With Collision Testimonials
Show off the great things people say about you, right on your WordPress site. Whether you want a dedicated page or a rotating sidebar widget, Collision Testimonials lets you display the kind words of happy clients wherever you want. You can even have a fo
blogging tools
Create An Easy Informative Website Tour For Your Site In Minutes With Amberjack
Wouldn't it be cool if you could go to a brand new website that you've never visited before, and just click a button to get a brief tour of the site? Well, now you can offer that service to your own website visitors. A very cool, free service called Amb
Need E-commerce Design? Check out our member profiles:
Founded in January, 2000, Peter Otte Productions is a professional graphic and web design firm that delivers custom ecommerce sites.
Santa Barbara, California US
We at I-Soft Solutions provide other web services which include Customized Static Web Design, Dynamic Web Development in PHP Mysql, Web Hosting, Domain Name Registrations, Website Maintains Etc.
Navi Mumbai, Maharashtra IN
2Heaven Media is a full service Web Development company that focuses on custom Website creation and E-Commerce Site Development.
Los Angeles, California US
Clarity Ventures is an Austin, TX based consulting company committed to building innovative web based solutions for our clients (e-commerce, content management, design, and SEO / marketing).
Austin, Texas US
AnS International specializes in web design, search engine optimization, web marketing, social media marketing, copywriting, and website hosting services. We are based out of Colorado.
Fort Collins, Colorado US
Cheung Vong is a graphic/web designer who specializes in print, web, video and multimedia.
Bellingham, Washington US
MMV Solutions provides businesses and individuals high quality web design, web marketing, web hosting, SEO (search engine optimization), computer repair (within the atlanta area), Ecommerce, and more!
Stockbridge, Georgia USThe 5 Best Battlefield 3 Websites For Up To The Minute Information
Battlefield 3 is being hyped as the Call of Duty killer That is no small task considering that Call
Cool Websites and Tools [March 11th 2012]
Check out some of the latest MakeUseOf discoveries Most of the listed websites are FREE or come wit
Tweet On The Go Like A Pro With This Killer Combo Of Apps [Android]
Ah that most addictive of Internet birds Twitter No doubt it s fun to tweet and even more fun t
10 Great ifttt Recipes To Automate Your Web Life
We ve already introduced you to ifttt in a previous post and there have been several improvements ma
25 Brand New iOS App Icons for Design Inspiration
img src http rss buysellads com img php z 1264761 k bb78eac5744533b69852b62261051c57 a 1384
13 Fresh, Exciting iPad Apps Added to the Best iPad Apps Page
Our Best iPad Apps has recently undergone a full overhaul 13 fresh applications have been included
Sony Pictures Online Hacked Using “Primitive and Common” Vulnerability, Data Unencrypted [News]
On Thursday evening hacker group LulzSec announced via Twitter that they had gained access to Son
Article Tags
E-commerce Design Articles
Web Apps & Internet (374)
News (291)
Web Apps (129)
Inspiration (128)
Music (119)
iPhone / iPad / iPod (116)
cool web apps (108)
Google Android (101)
Mobile Tips (100)
Announcements (99)
deals (88)
Games & Gaming Tips (84)
Tech Deals (82)
Opinion & Polls (76)
Cool Software Apps (76)
Social Media (66)
iOS (66)
Browser Tips & Tricks (66)
iPhone Apps (59)
Freebies (58)
geeky fun (58)
Photography (58)
iphone (55)
Google (53)
troubleshoot (53)
android (52)
Photoshop (52)
Graphics (51)
facebook (50)
How-To Articles (50)
Friends:
E-Commerce Website Pricing
Web Design Quote
Website Design
Graphic Designers