copy （ The whole system is backed up locally , Restore or restore to the local machine in the future ）
Note that there should be enough free space in the root directory for backup .
cd /#tar.gz Format tar cvpzf system_backup.tar.gz / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.gz --exclude=/mnt --exclude=/sys#tar.bz2 Format tar cvpjf system_backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.bz2 --exclude=/mnt --exclude=/sys# Recovery system cd /# Upload the file to the root directory tar xvpfz system_backup.tar.gz -C / or tar xvpfj system_backup.tar.bz2 -C /# Directory excluded when creating backup mkdir procmkdir lost+foundmkdir mntmkdir sys
- /proc jurisdiction ： File owner ：root group ：root owner ： Read perform group ： Read perform Other ： Read perform
- /lost+found jurisdiction ： File owner ：root group ：root owner ： Read write in perform group ： Read perform Other ： Read perform
- /mnt jurisdiction ： File owner ：root group ：root owner ： Read write in perform group ： Read perform Other ： Read perform
- /sys jurisdiction ： File owner ：root group ：root owner ： Read write in perform group ： Read perform Other ： Read perform
After the recovery is complete, restart , So everything will be as like as two peas .
Mirror image （ Local backup system , Restore to new host ）
1, Check the system version , Install the same version of the system on the target machine ( The simplest installation is enough ), Partition format , The same is true of the type （ I've never tried anything different , I don't know if it will succeed ）lsb_release -auname -adf -Thfree -h2, Backup source system # Because the hardware configuration of the target and the source host is different , So exclude dev,tmp; Add the files you want to exclude , Such as ：--exclude=/root/*.bz2# Here again mnt There is plenty of space below , So save it to mnt Next .cd /tar cvpzf /mnt/system_backup.tar.gz / --exclude=/mnt/system_backup.tar.gz \--exclude=/proc --exclude=/lost+found --exclude=/mnt --exclude=/sys --exclude=/dev \--exclude=/tmp --exclude=/media# Upload to target host scp /mnt/system_backup.tar.gz firstname.lastname@example.org:/mnt3, On target ISO、LiveCD Wait to start , Mount the disk （ It is usually automatically mounted to the /media Folder ）sudo -s cd /media/< Corresponding uuid Number ># Backup important configuration files /boot/gurb/gurb.cfg /etc/fstab In the record UUID,# Delete duplicate files # Except for some of the folders excluded when backing up your system , for instance dev mnt media sys These folders , Delete all others .rm -rf root home usr lib lib64 etc var bin sbin opt boot run selinux vmlinuz initrd.img# Restore backup mount /dev/vda1 /mnt/1# Don't write here / Catalog , We'll hook up the existing system ！！！ It should be the mounted directory tar xvpfz system_backup.tar.gz -C /mnt/1cd /mnt/1 # At this point you can see the structure of the root directory , But the editor fstab File discovery is in the existing system fstabchroot ./ # perform chroot Later, I will use ./ The directory is the root , At this point, the edited file is the real target source file . Modify after restore /etc/fstab Inside UUID For the information in the file just backed up , Note that the partition format should also correspond to . modify /boot/gurb/gurb.cfg Inside UUID For the information in the file just backed up . Modify NIC 、IP The configuration file , In case it can't be allocated IP.（ If it's a virtual machine, remember to add a network card , Configuration of medium performance graphics card ） If there are services that depend on the original platform , If built-in NTP,Agent And other monitoring procedures ; Close the service , Turn off and start automatically ;Ubuntu： Enter at the command line runleve You can view the current run level , The general default is 2 see /etc/rc2.d In the directory S At the beginning, the service will start automatically ; There are soft links in it , If you want to add it, you can create a link file ,S representative start, The following number is the starting sequence , Delete soft links . At the same time to delete /etc/init.d/ Under the corresponding script .vim /etc/init.d/rc.localCentos: use systemctl After completing the above steps exit # sign out chrootcd ~umount /mnt/1# When it's done, you can restart , The system starts normally without accident （ After startup, the account set when the original system was installed disappears ; The account is consistent with the source host ）. If on Grub Tips “boot error 15 :Error 15 file not found” resolvent ： Please check GRUB The location of the kernel file of the related file . Usually with /boot Partition related . If on Grub Tips “dracut:dono't how to hand root=f078” resolvent ： take root=UUID Change to root=/dev/sdaX This format . If the system prompts /usr/libexec/gconf-sanity-check-2 Exit state 256 The solution to this problem ：chmod 777 /tmp
Note that the format of the target partition is best NTFS、FAT、EXT And so on , Avoid encountering greater than 4G Can't be backed up .
# It's better to have other partitions or external storage devices , Mount well ,df -lh Look at the mount point .# Backup rsync -Pa / /media/usb/backup_20170410 --exclude=/media/* --exclude=/sys/* --exclude=/proc/* --exclude=/mnt/* --exclude=/tmp/*# recovery rsync -Pa /media/usb/backup_20170410 /
dd The command belongs to a sector clone , The target partition is larger than the backup partition , Even unused space can be cloned as it is , It will be slow .
# Backup df -h # View system partition dd if=/dev/sda1 of=/dev/sdb3 # Backup sda1 To sdb3 in # recovery dd if=/dev/sdb3 of=/dev/sda1 # recovery sdb3 To sdb1 in
That's all Liangxu tutorial website For all of you Linux Related knowledge .