October 22, 2015

How to backup a full Centos Server?

Method 1:
The best tool to use for this is probably dump, which is a standard linux tool and will give you the whole filesystem. I would do something like this:
/sbin/dump -0uan -f - / | gzip -2 | ssh -c blowfish user@backupserver.example.com dd of=/backup/server-full-backup-`date '+%d-%B-%Y'`.dump.gz
This will do a file system dump of / (make sure you don't need to dump any other mounts!), compress it with gzip and ssh it to a remote server (backupserver.example.com), storing it in /backup/. If you later need to browse the backup you use restore:
restore -i
Another option, if you don't have access to dump is to use tar and do something like
tar -zcvpf /backup/full-backup-`date '+%d-%B-%Y'`.tar.gz --directory / --exclude=mnt --exclude=proc --exclude=tmp .
But tar does not handle changes in the file system as
http://serverfault.com/questions/120431/how-to-backup-a-full-centos-server

Method 2:
Backup Your Server's OS             
Making a backup of your Linux Operating System is a very simple process that uses tools included in every linux installation.                The first step is to create a location to store the backup. For this article we're going to store the backup on the same hard drive as the installed operating system, but you can attach USB devices like thumb drive and external hard drives and even special storage like iSCSI and NFS mounted device to store the backup.      Once you are logged into the server and at a command line make the directory to store the backup in an organized way such as:     
mkdir /backups
Now we will create a compressed version of the Operating System in one single file (tarball) using the tar command.     
For RedHat, CentOS and Fedora or any Operating System based on these linux flavors run the following command:        
tar cvpzf /backups/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/sysconfig/network-scripts/ --exclude=/etc/udev/rules.d/70-persistent-net.rules /   
For Debian or Ubuntu run the following command:         
tar cvpzf /backups/backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backups --exclude=/dev --exclude=/sys --exclude=/boot/grub --exclude=/etc/fstab --exclude=/etc/network/interfaces --exclude=/etc/udev/rules.d/70-persistent-net.rules /   
Once the command completes the tarball will be located at /backups/backup.tgz            
***HINT: You can change the name of the tarball file with a date identifier and keep multiple versions or "snapshots" of your server's configuration.       
Restore Your Server's OS From a Backup             
In order to restore your server from the previously created tarball the server must have the same Operating System version loaded on it. This particular method of backup and restore is not meant for bare metal projects that need to restore an Operating System to an empty hard drive. It was actually designed to move a configured Operating System from one hardware platform to another, but also works well for rolling back an operating system to a previous configuration.               
Once you have a working Operating System either on a new hardware platform or the same hardware platform move the tarball to the server you want to restore. If you stored the tarball on a USB device or other external storage just reattach the device and mount it. If the tarball is on another linux server use commands like this to copy it to the new server’s hard drive:   
mkdir /backups
scp root@original_server:/backups/backup.tgz /backups            
Of course replace "original_server" with the appropriate IP address.Enter the root users password and the transfer will begin.   Once the transfer has completed run this command to extract the tarball thereby restoring the Operating System that the tarball contains:              
tar xvpfz /backups/backup.tgz -C /
Complete the process with a reboot and troubleshoot any errors that may come up.     
https://www.serverpronto.com/kb/page.php?id=Backing+Up+and+Restore+Your+Server

Method 3:
Ok. The best way to go about this is using rsync. Install rsync on the VPS if it isn't already (probably is).
I am assuming that you have ssh server on the machine where you want the backup (your new VPS?) and that it is listening on the standard port 22.
On the machine where the backup will go, make a new directory called VPSbackup or whatever. Below you can see in the example I assume it is at /home/myuser/VPSbackup.
On your VPS, run:
 rsync -avz --exclude=/proc --exclude=/sys --exclude=/dev -e ssh / myuser@my_ip_address:/home/myuser/VPSbackup
You will then type in the password for myuser when you are prompted, and the backup will begin.
You can also do it in reverse, if you want to use rsync from the local machine (maybe you are behind NAT and/or don't have a public listening ssh server on the backup machine) like so:
rsync -avz --exclude=/proc --exclude=/sys --exclude=/dev -e ssh root@vps_ip_address:/ /home/myuser/VPSbackup
In either case, be patient---it'll take a while :-)
To restore the backup to your new VPS, first install the same version of CentOS on the VPS (just a vanilla install with SSH server) and copy the backup on to it.
From the new VPS:
rsync -avz -e ssh myuser@my_ip_address:/home/myuser/VPSbackup/* /
OR from the machine where the backup is:
rsync -avz -e ssh /home/myuser/VPSbackup/* root@new_vps_ip_address:/
Note that doing it using rsync will copy all the files on your VPS to the VPSbackup directory on the backup machine. If you want everything is one big backup file, then you may want to use tar via ssh like so (on the VPS machine):
tar zcvf - --exclude=/proc --exclude=/sys --exclude=/dev  / | ssh myuser@backupmachine_ip_addr "cat > /home/myuser/VPSbackup.tar.gz"
Then to restore to the new VPS (run this on the new VPS):
cd /
ssh myuser@backupmachine_ip_addr "cat /home/myuser/VPSbackup.tar.gz" | tar zxvf -

http://www.experts-exchange.com/OS/Linux/Q_28429417.html



                                          

Related Posts:

  • VPS căn bản [Phần 10] – Cài đặt WordPress Trải qua 8 phần chắc bạn cũng đã nóng lòng cần biết qua cách cài đặt WordPress trên VPS rồi. Thật ra nếu bạn đã có kinh nghiệm dùng Shared Host thì chỉ đọc hết bài MySQL là đã có thể tự cài đặt WordPress được. Và … Read More
  • Chuyển thư mục lên RAM để tăng tốc website Chuyển thư mục lên RAM để tăng tốc website Chắc hẳn các bạn đều biết, RAM có tốc độ nhanh hơn ổ cứng rất nhiều nên ý tưởng chuyển thư mục hay tập tin lên RAM là ý tưởng khá hay để tăng… Read More
  • Tạo crontab tự động bật lại MySQL khi bị stop trên VPS/Server Với những VPS có RAM ít và bạn không rõ về config MySQL dẫn tới hiện tượng thi thoảng website quá tải và bị lỗi không thể kết nối tới database. Bài viết này sẽ hướng dẫn bạn cách khắc phục lỗi chết MySQL và tạo crontab&… Read More
  • Tự động backup database và sao lưu FTP trên VPS chạy LNMP Dữ liệu, đối với bất kỳ cá nhân/doanh nghiệp nào cũng đều rất quan trọng. Giờ đây, người người có web, nhà nhà có web là chuyện bình thường như cô Hường lên phường. Tuy nhiên, vấn đề backup dữ liệu không phải ai cũ… Read More
  • How to backup a full Centos Server? Method 1: The best tool to use for this is probably dump, which is a standard linux tool and will give you the whole filesystem. I would do something like this: /sbin/dump -0uan -f - / | gzip -2 | ssh -c blowfish user@back… Read More

2 comments:

  1. trying method 2 on CentOS 6.6 but unable to boot!

    ReplyDelete
  2. trying method 2 on CentOS 6.6 but unable to boot!

    ReplyDelete