


Commonly used Linux system backup and recovery commands

cd / #tar.gz格式 tar cvpzf system_backup.tar.gz / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.gz --exclude=/mnt --exclude=/sys #tar.bz2格式 tar cvpjf system_backup.tar.bz2 / --exclude=/proc --exclude=/lost+found --exclude=/system_backup.tar.bz2 --exclude=/mnt --exclude=/sys # 恢复系统 cd / #上传文件到根目录下 tar xvpfz system_backup.tar.gz -C / 或 tar xvpfj system_backup.tar.bz2 -C / #创建备份时排除的目录 mkdir proc mkdir lost+found mkdir mnt mkdir sys
/proc Permissions: File Owner: root Group: root Owner: Read Execution Group: Read Execution Other: Read Execution /lost found Permissions: File Owner: root Group: root Owner: Read Write Execution Group: Read Execute Others: Read Execute /mnt Permissions: File Owner: root Group: root Owner: Read Write Execution Group: Read Execute Others: Read Execute /sys 权限:文件所有者:root群组:root 所有者:读取 写入 执行 群组:读取 执行 其它:读取 执行
搜索公众号Linux中文社区后台回复“私房菜”,获取一份惊喜礼包。
恢复完成重启以后,所以的事情都会和你备份的时候一模一样。
镜像(本机备份系统,还原到新主机上)
1,检查系统版本,在目标机上安装一样版本的系统(最简安装即可),分区格式,类型也一样(我没试过不一样的情况,不知道能否成功)
lsb_release -a uname -a df -Th free -h
2,备份源系统
# 因为目标机和源主机硬件配置不同,所以排除dev,tmp;再适当增加你要排除的文件,如:--exclude=/root/*.bz2 # 这里再mnt下有充足空间,所以保存到mnt下。 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 # 上传到目标主机 scp /mnt/system_backup.tar.gz root@192.168.0.166:/mnt
3,在目标机上用ISO、LiveCD等启动,挂载磁盘(一般会自动挂载到/media文件夹)
sudo -s cd /media/<对应的uuid号> # 备份重要配置文件/boot/gurb/gurb.cfg /etc/fstab 记录里面的UUID, # 删除重复文件 # 除了上面备份系统时排除的一些文件夹外,比如说dev mnt media sys这些文件夹,其他全部删除。 rm -rf root home usr lib lib64 etc var bin sbin opt boot run selinux vmlinuz initrd.img # 还原备份 mount /dev/vda1 /mnt/1 # 这里注意千万不要写/目录,会把现有的系统搞挂!!!应该是挂载的目录 tar xvpfz system_backup.tar.gz -C /mnt/1 cd /mnt/1 #此时你可以看到根目录的结构,但是编辑fstab文件发现是现有系统的fstab chroot ./ #执行chroot后会以./目录为根目录,这时编辑的文件就是真正的目标源文件了。
还原后修改/etc/fstab里的UUID为刚刚备份的文件里面的信息,注意分区格式也要对应。
修改/boot/gurb/gurb.cfg里的UUID为刚刚备份的文件里面的信息。修改网卡、IP配置文件,以防无法分配IP。(如果是虚拟机记得添加网卡,配置中等性能的显卡)
如果有依赖于原有平台的服务,如内建NTP,Agent等监控程序;关闭服务,关闭开机自启;
Ubuntu:在命令行输入runleve可以查看当前运行级别,一般默认是2
查看/etc/rc2.d目录中的S开头的服务都是会开机自动运行的;里面是软链接,想添加的话自己建一个链接文件就可以,S代表start,后面数字是启动顺序,删除软链接。同时删除/etc/init.d/下对应的脚本。
vim /etc/init.d/rc.local Centos:用systemctl
完成上述步骤后
exit #退出chroot cd ~ umount /mnt/1 # 一切完成后就可以重启了,不出意外就正常启动系统了(启动后原来安装系统时设置的账户等全部消失;账户和源主机一致)。 若开机Grub提示“boot error 15 :Error 15 file not found” 解决方法:请检查GRUB相关文件的内核文件所在位置。通常与/boot分区有关。 若开机Grub提示“dracut:dono't how to hand root=f078” 解决方法:将root=UUID改成root=/dev/sdaX这种格式。 若开机系统提示/usr/libexec/gconf-sanity-check-2退出状态256的解决 解决方法:chmod 777 /tmp
rsync命令
注意目标分区的格式最好是NTFS、FAT、EXT之类的格式,避免遇到大于4G的文件无法备份的问题。
#最好有其他分区或外接存储设备,挂载好,df -lh看挂载点。 #备份 rsync -Pa / /media/usb/backup_20170410 --exclude=/media/* --exclude=/sys/* --exclude=/proc/* --exclude=/mnt/* --exclude=/tmp/* #恢复 rsync -Pa /media/usb/backup_20170410 /
dd命令
dd命令属于扇区克隆,目标分区要比备份分区要大,即使没有使用的空间也会被原样克隆下来,会比较慢。
#备份 df -h #查看系统所在分区 dd if=/dev/sda1 of=/dev/sdb3 #备份sda1到sdb3中 #恢复 dd if=/dev/sdb3 of=/dev/sda1 #恢复sdb3到sdb1中
The above is the detailed content of Commonly used Linux system backup and recovery commands. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

Gate.io is a highly acclaimed cryptocurrency trading platform known for its extensive token selection, low transaction fees and a user-friendly interface. With its advanced security features and excellent customer service, Gate.io provides traders with a reliable and convenient cryptocurrency trading environment. If you want to join Gate.io, please click the link provided to download the official registration installation package to start your cryptocurrency trading journey.

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...
