Go Back   Singapore Web Hosting Talk > LEARNING CENTER > Server Administration

Server Administration General dedicated servers administration topics.

Reply
 
Thread Tools
Old 16-10-2003, 11:26   #1
choon
SGWHT Senior Member
 
Join Date: 01-07-2002
Location: Singapore
Posts: 488
choon has a spectacular aura aboutchoon has a spectacular aura about
HOW TO: Backup and Restore your site & MySQL DB using SSH

This guide is suitable for those people who has SSH access to their accounts.

As always, follow at your own risk and I am not responsible for any damages caused. You have been warned!!!

Step 1: Login your normal user account via SSH.

Step 2: MySQL DB backup
Make a sub directory name mysqlbackup under your home directory.
Code:
mkdir ~/mysqlbackup
Now issue the following command to backup your MySQL DB to the mysqlbackup directory:
Code:
mysqldump -u MYSQLUSERNAME -pMYSQLPASSWORD --add-drop-table MYSQLDBNAME > ~/mysqlbackup-`date '+%d-%B-%Y'`.sql
Where
MYSQLUSERNAME is your MySQL Username
MYSQLPASSWORD is your MySQL Password
MYSQLNAME is your MySQL Database Name
If you have more than one MySQL DBs, simply change MYSQLUSERNAME, MYSQLPASSWORD and MYSQLDBNAME accordingly.
The above command will dump your DB to mysqlbackup directory.

Step 3: Backup your account
Now it is time to create a backup sub directory under your home directory. I will create sub directory name backup.
Code:
mkdir ~/backup
It is time to backup your account including MySQL DBs. There are many methods to backup your account but I will just list down one though.
Issue the following command to have all your data in your account backup except those in your backup directory:
Code:
cd
tar -zcpvf ~/backup/fullbackup-`date '+%d-%B-%Y'`.tar.gz --exclude=backup .
First command is to change your current working directory to your home directory.
Second command is to backup all your data in your account except those in the backup directory. Remember the ending dot at the end of the second command.

Now you can FTP in and download the tarball in the backup directory.

HOW TO RESTORE FROM BACKUP?

Here are the steps:

Step 1. FTP upload one of your latest backup tarball to your account which is in fullbackup-DD-Month-YYYY.tar.gz.

Step 2: SSH in your account.

Step 3: Create a temp. directory in your account.
For me, I will create restore directory name under home directory.
Code:
mkdir ~/restore
Step 4: Move your uploaded latest backup tarball to the restore directory.
If you upload the backup tarball in your home directory, simply issue this command:
Code:
mv fullbackup-*.tar.gz ~/restore/
Step 5: Change your current working directory to your restore directory.
Issue this command to change:
Code:
cd ~/restore
Step 6: Unpack your uploaded backup tarball in the restore directory.
Code:
tar -zxvf fullbackup-*.tar.gz
Now it is time for you to move whatever files or directory as you wish from your restore directory to your home directory. This requires you to have some basic knowledge in SSH command though. I don't want to unpack the backup tarball in the home directory is because I can choose to restore on whatever files or directories I want to restore from backup

For restore your MySQL DBs, issue the following command:
Code:
mysql -u MYSQLUSERNAME -pMYSQLPASSWORD MYSQLDBNAME < MYSQLDBNAME-choose-the-date.sql

Ok, I am done.

Hope this help someone

<EDIT>edit some typo :p</EDIT>
__________________
Giam Teck Choon
System Administrator
Join my community today at choon.NET Community to share server related tips and tricks!
External/One-Year WHM/cPanel licenses | Linux/FreeBSD Server Management | Xen VPS Solutions (with/without WHM/cPanel or DirectAdmin)

Last edited by choon; 16-10-2003 at 12:20.
choon is offline   Reply With Quote

Old 16-12-2003, 18:32   #2
freesky
SGWHT Newbie
 
Join Date: 16-12-2003
Posts: 1
freesky is on a distinguished road
great..thx
freesky is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT +8. The time now is 23:38.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright (C) 2002-2015 Brought to you by Singapore Web Hosting Talk (SGWHT). All Rights Reserved.