Ubuntu 16.04 backup and recovery summary

  • 2020-05-12 06:45:59
  • OfStack

preface

In the backup of the main need to confirm which directory does not need to be backed up, although there are many online backup tutorial, but still need to adjust the parameters according to their own situation.

1. Clean the cache, recycle bin, etc


#  Clean up the old version of the software cache 
sudo apt-get autoclean
#
#  Clean up all software caches 
sudo apt-get clean
#
#  Remove isolated software that is no longer used by the system 
sudo apt-get autoremove

2. Use TAR backup

1. Explanation of commands and parameters

v: displays detailed compression information

c: create the tar package

j: use the bzip2 compression format

z: use the gzip compression format

p: use absolute paths

f: path to the generated compressed file

2. Terminal operation


#  Switch to the root identity 
su - root
#
#  use gzip Compressed format (slightly lower but faster) 
tar vzcpf /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.tar.gz --exclude=/proc --exclude=/dev --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/cdrom --exclude=/tmp --exclude=/sys --exclude=/home/chris/.cache --exclude=/run / > /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.log 2> /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.error
#
#  use bzip2 Compression format (slightly higher compression, but slower) 
tar vjcpf /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.tar.bz2 --exclude=/proc --exclude=/dev --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/cdrom --exclude=/tmp --exclude=/sys --exclude=/home/chris/.cache --exclude=/run / > /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.log 2> /media/chris/LinuxData/Backup/ubuntu_`date +%Y%m%d_%H`.error

3. Restore the system

1, recommended backup: /boot and /etc/fstab, and then execute the restore command

2. Copy the backup file to/directory and execute the restore command:


#  use gzip format 
su - root
tar vxzpf ubuntu*.tar.gz -C /
#
#  use bzip2 format 
tar vxjpf ubuntu*.tar.bz2 -C /

conclusion

The above is the whole content of this article, I hope the content of this article can help you in your study or work, if you have any questions, you can leave a message to communicate.


Related articles: