Linux ~ 备份与恢复。
文章目录
备份。
Linux 需要备份的数据。
-
/root/
-
/home/
-
/var/spool/mail/
-
/etc/
-
其他。
服务器(eg. Apache)需要备份的数据。
- 配置文件。
- 网页主目录。
- 日志文件。
MySQL 需要备份的数据。
- 源码包安装的 MySQL:/usr/local/mysql/data/ ——> 5.5 版本后。(5.5 前 ——> /usr/local/mysql/var)。
- RPM 包安装的 MySQL:/var/lib/mysql/
备份策略。
- 完全备份。
把所有需要备份的数据全部备份。当然完全备份可以备份整块硬盘,整个分区或某个具体目录。
- 增量备份。
第一天备份全部数据,以后每天备份增量数据。
恢复麻烦。
- 差异备份。
每次都和完全备份的数据比较(第一天)。
备份命令 ~ 适用于增量备份。
dump。
[root@localhost ~]# rpm -qa | grep dump
tcpdump-4.0.0-11.20090921gitdf3cb4.2.el6.x86_64
默认没有安装。以上是抓包命令。
[root@localhost ~]# yum install dump
[root@localhost ~]# dump [选项] 备份之后的文件名 原文件或目录
选项。
-level。——> 0 ~ 9 十个备份级别。(-0 完全备份)。
-f 文件名。——> 指定备份之后的文件名。
-u。——> 备份成功之后,把备份时间记录在 /etc/dumpdates 文件。
-v。——> 显示备份过程中更多的输出信息。
-j。——> 调用 bzlib 库压缩备份文件。其实就是把备份文件压缩为 .bz2 格式。
-W。——> 显示允许被 dump 的分区备份等级助记词备份时间。
[root@localhost ~]# dump -0uj -f ~/boot.bak.bz2 /boot/
DUMP: Date of this level 0 dump: Mon Mar 16 21:38:07 2020
DUMP: Dumping /dev/sda1 (/boot) to /root/boot.bak.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 51141 blocks.
DUMP: Volume 1 started with block 1 at: Mon Mar 16 21:38:07 2020
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /root/boot.bak.bz2
DUMP: Volume 1 completed at: Mon Mar 16 21:38:31 2020
DUMP: Volume 1 took 0:00:24
DUMP: Volume 1 transfer rate: 1934 kB/s
DUMP: Volume 1 51290kB uncompressed, 46430kB compressed, 1.105:1
DUMP: 51290 blocks (50.09MB) on 1 volume(s)
DUMP: finished in 24 seconds, throughput 2137 kBytes/sec
DUMP: Date of this level 0 dump: Mon Mar 16 21:38:07 2020
DUMP: Date this dump completed: Mon Mar 16 21:38:31 2020
DUMP: Average transfer rate: 1934 kB/s
DUMP: Wrote 51290kB uncompressed, 46430kB compressed, 1.105:1
DUMP: DUMP IS DONE
[root@localhost ~]# cat /etc/dumpdates
/dev/sda1 0 Mon Mar 16 21:38:07 2020 +0800
[root@localhost ~]# cp install.log /boot/
[root@localhost ~]# dump -1uj -f ~/boot1.bak.bz2 /boot/
DUMP: Date of this level 1 dump: Mon Mar 16 21:41:01 2020
DUMP: Date of last level 0 dump: Mon Mar 16 21:38:07 2020
DUMP: Dumping /dev/sda1 (/boot) to /root/boot1.bak.bz2
DUMP: Label: none
DUMP: Writing 10 Kilobyte records
DUMP: Compressing output at compression level 2 (bzlib)
DUMP: mapping (Pass I) [regular files]
DUMP: mapping (Pass II) [directories]
DUMP: estimated 56 blocks.
DUMP: Volume 1 started with block 1 at: Mon Mar 16 21:41:01 2020
DUMP: dumping (Pass III) [directories]
DUMP: dumping (Pass IV) [regular files]
DUMP: Closing /root/boot1.bak.bz2
DUMP: Volume 1 completed at: Mon Mar 16 21:41:02 2020
DUMP: Volume 1 took 0:00:01
DUMP: Volume 1 transfer rate: 13 kB/s
DUMP: Volume 1 60kB uncompressed, 13kB compressed, 4.616:1
DUMP: 60 blocks (0.06MB) on 1 volume(s)
DUMP: finished in less than a second
DUMP: Date of this level 1 dump: Mon Mar 16 21:41:01 2020
DUMP: Date this dump completed: Mon Mar 16 21:41:02 2020
DUMP: Average transfer rate: 13 kB/s
DUMP: Wrote 60kB uncompressed, 13kB compressed, 4.616:1
DUMP: DUMP IS DONE
[root@localhost ~]# cat /etc/dumpdates
/dev/sda1 0 Mon Mar 16 21:38:07 2020 +0800
/dev/sda1 1 Mon Mar 16 21:41:01 2020 +0800
[root@localhost ~]# dump -W
Last dump(s) done (Dump '>' file systems):
> /dev/mapper/VolGroup-lv_root ( /) Last dump: never
/dev/sda1 ( /boot) Last dump: Level 1, Date Mon Mar 16 21:41:01 2020
备份文件或目录。
dump -0j /root/etc.dump.bz2 /etc/
// 完成备份 /etc/ 目录。只能使用 0 级别进行完全备份,而不再支持增量备份。
restore。
[root@localhost ~]# restore [模式选项] [选项]
模式选项:restore 命令常用模式有如下 4 种,不能混用。
-C。——> 比较备份数据和实际数据的变化。
-i。——> 进入交互模式,手工选择需要恢复的文件。
-t。——> 查看模式,用于查看备份文件中拥有哪些数据。
-r。——> 还原模式,用于还原数据。
选项。
-f。——> 指定备份文件的文件名。
[root@localhost ~]# restore -C -f ~/boot.bak.bz2
Dump tape is compressed.
Dump date: Mon Mar 16 21:38:07 2020
Dumped from: the epoch
Level 0 dump of /boot on localhost.localdomain:/dev/sda1
Label: none
filesys = /boot
[root@localhost ~]# restore -t -f ~/boot.bak.bz2
Dump tape is compressed.
Dump date: Mon Mar 16 21:38:07 2020
Dumped from: the epoch
Level 0 dump of /boot on localhost.localdomain:/dev/sda1
Label: none
2 .
11 ./lost+found
65025 ./grub
65031 ./grub/grub.conf
65026 ./grub/splash.xpm.gz
65032 ./grub/menu.lst
65033 ./grub/device.map
65034 ./grub/stage1
65035 ./grub/stage2
65036 ./grub/e2fs_stage1_5
65037 ./grub/fat_stage1_5
65038 ./grub/ffs_stage1_5
65039 ./grub/iso9660_stage1_5
65040 ./grub/jfs_stage1_5
65041 ./grub/minix_stage1_5
65042 ./grub/reiserfs_stage1_5
65043 ./grub/ufs2_stage1_5
65044 ./grub/vstafs_stage1_5
65045 ./grub/xfs_stage1_5
65027 ./efi
65028 ./efi/EFI
65029 ./efi/EFI/redhat
65030 ./efi/EFI/redhat/grub.efi
12 ./.vmlinuz-2.6.32-754.el6.x86_64.hmac
13 ./System.map-2.6.32-754.el6.x86_64
14 ./config-2.6.32-754.el6.x86_64
15 ./symvers-2.6.32-754.el6.x86_64.gz
16 ./vmlinuz-2.6.32-754.el6.x86_64
17 ./initramfs-2.6.32-754.el6.x86_64.img
23 ./initramfs-2.6.32-754.27.1.el6.x86_64.img
18 ./.vmlinuz-2.6.32-754.27.1.el6.x86_64.hmac
19 ./System.map-2.6.32-754.27.1.el6.x86_64
20 ./config-2.6.32-754.27.1.el6.x86_64
21 ./symvers-2.6.32-754.27.1.el6.x86_64.gz
22 ./vmlinuz-2.6.32-754.27.1.el6.x86_64
[root@localhost ~]#