



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!

The reason for mastering Linux operations is its wide range of application scenarios and powerful functions. 1) Linux is suitable for developers, system administrators and technology enthusiasts, and is used in server management, embedded systems and containerization technologies. 2) Learning Linux can start with file system structure, shell usage, user permission management and process management. 3) The Linux command line is its core tool, which executes commands through the shell, such as ls, mkdir, cd, etc., and supports redirection and pipeline operations. 4) Advanced usage includes writing automated scripts, such as backup scripts, using tar commands and conditional judgments. 5) Common errors include permissions, paths and syntax issues, which can be debugged through echo, set-x and $?. 6) Performance optimization suggestions

The five pillars of the Linux system are: 1. Kernel, 2. System library, 3. Shell, 4. File system, 5. System tools. The kernel manages hardware resources and provides basic services; the system library provides precompiled functions for applications; the shell is the interface for users to interact with the system; the file system organizes and stores data; and system tools are used for system management and maintenance.

In Linux systems, maintenance mode can be entered by pressing a specific key at startup or using a command such as "sudosystemctlrescue". Maintenance mode allows administrators to perform system maintenance and troubleshooting without interference, such as repairing file systems, resetting passwords, patching security vulnerabilities, etc.

Linux beginners should master basic operations such as file management, user management and network configuration. 1) File management: Use mkdir, touch, ls, rm, mv, and CP commands. 2) User management: Use useradd, passwd, userdel, and usermod commands. 3) Network configuration: Use ifconfig, echo, and ufw commands. These operations are the basis of Linux system management, and mastering them can effectively manage the system.

The article explains how to manage sudo privileges in Linux, including granting, revoking, and best practices for security. Key focus is on editing /etc/sudoers safely and limiting access.Character count: 159

The article provides a guide on setting up two-factor authentication (2FA) for SSH on Linux using Google Authenticator, detailing installation, configuration, and troubleshooting steps. It highlights the security benefits of 2FA, such as enhanced sec

The article discusses using top, htop, and vmstat for monitoring Linux system performance, detailing their unique features and customization options for effective system management.

Article discusses managing software packages in Linux using apt, yum, and dnf, covering installation, updates, and removals. It compares their functionalities and suitability for different distributions.


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

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function