


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.
