在使用Dump工具备份文件系统时必须被卸载或是挂载成只读形式,Dump工具也能备份单独的目录,但是限制比较多,功能不是很完善。支持两种备份方式,支持10种级别的定制备份方式。

完全备份:0

差异备份:1-9

 

 

 

[root@szm ~]# man dump

 

SYNOPSIS

       dump  [-level#]-指定数据备份的级别 [-ackMnqSuv] [-A file]-指定备份时的存档文件 [-B records] [-b blocksize]-备份时指定数据块大小 [-d density] [-D file] [-e inode num-

       bers] [-E file] [-f file]-将备份的数据保存为文件 [-F script] [-h level] [-I nr errors] [-jcompression  level]  [-L  label]  [-Q

       file] [-s feet] [-T date] [-y] [-zcompression level] files-to-dump

       dump [-W | -w]

-u:将备份的时间记录到/etc/dumpdates文件内

-v:显示备份过程

-W:列出/etc/fstab分区中设置有备份的分区是否备份过

-S:查看备份数据的容量

 

[root@szm Desktop]# yum install dump

[root@szm dump]# dump -0u -f ./home.$(date +%Y-%m-%d).dump /home
  DUMP: You can't update the dumpdates file when dumping a subdirectory
  DUMP: The ENTIRE dump is aborted.
 当备份子目录时,不能使用u参数
 
[root@szm dump]# dump -0 -f ./home.$(date +%Y-%m-%d).dump /home
  DUMP: Date of this level 0 dump: Tue Mar 12 09:56:08 2013
  DUMP: Dumping /dev/mapper/vg_szm-lv_root (/ (dir home)) to ./home.2013-03-12.dump
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 340020 blocks.
  DUMP: Volume 1 started with block 1 at: Tue Mar 12 09:56:10 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing ./home.2013-03-12.dump
  DUMP: Volume 1 completed at: Tue Mar 12 09:57:08 2013
  DUMP: Volume 1 341510 blocks (333.51MB)
  DUMP: Volume 1 took 0:00:58
  DUMP: Volume 1 transfer rate: 5888 kB/s
  DUMP: 341510 blocks (333.51MB) on 1 volume(s)
  DUMP: finished in 58 seconds, throughput 5888 kBytes/sec
  DUMP: Date of this level 0 dump: Tue Mar 12 09:56:08 2013
  DUMP: Date this dump completed:  Tue Mar 12 09:57:08 2013
  DUMP: Average transfer rate: 5888 kB/s
  DUMP: DUMP IS DONE
 
[root@szm dump]# ls -lh 
total 334M
-rw-r--r--. 1 root root 334M Mar 12 09:57 home.2013-03-12.dump
 
[root@szm dump]# cat /etc/dumpdates

 

 

[root@szm dump]# dump -1 -f ./home-level1.dump /home/

  DUMP: Only level 0 dumps are allowed on a subdirectory

  DUMP: The ENTIRE dump is aborted.

 只有Level0级别能使用在子目录中

 

 [root@szm dump]# dump -0u -f /mnt/sdb6/test.level1.dump /mnt/sdb7
  DUMP: Date of this level 0 dump: Tue Mar 12 16:48:38 2013
  DUMP: Dumping /dev/sdb7 (/mnt/sdb7) to /mnt/sdb6/test.level1.dump
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 25 blocks.
  DUMP: Volume 1 started with block 1 at: Tue Mar 12 16:48:39 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /mnt/sdb6/test.level1.dump
  DUMP: Volume 1 completed at: Tue Mar 12 16:48:39 2013
  DUMP: Volume 1 20 blocks (0.02MB)
  DUMP: 20 blocks (0.02MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 0 dump: Tue Mar 12 16:48:38 2013
  DUMP: Date this dump completed:  Tue Mar 12 16:48:39 2013
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE
 

 [root@szm dump]# ll /mnt/sdb6/
total 34
drwx------. 2 root root 12288 Mar 12 16:36 lost+found
-rw-r--r--. 1 root root 20480 Mar 12 16:48 test.level1.dump
[root@szm dump]# cat /etc/dumpdates
/dev/sdb7 0 Tue Mar 12 16:48:38 2013 +0800----------完成备份时间

[root@szm dump]# dump -W---------------查看已经做过数据备份的分区
Last dump(s) done (Dump '>' file systems):
> /dev/mapper/vg_szm-lv_root (     /) Last dump: never
> /dev/sda1 ( /boot) Last dump: never
  /dev/sdb6 (/mnt/sdb6) Last dump: never
  /dev/sdb7 (/mnt/sdb7) Last dump: Level 0, Date Tue Mar 12 16:48:38 2013
 

[root@szm dump]# dump -0z -f /mnt/sdb7/mail.dump.gz /var/spool/mail------使用gzip压缩

  DUMP: Date of this level 0 dump: Tue Mar 12 16:53:40 2013
  DUMP: Dumping /dev/mapper/vg_szm-lv_root (/ (dir var/spool/mail)) to /mnt/sdb7/mail.dump.gz
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: Compressing output at compression level 2 (zlib)
  DUMP: mapping (Pass I) [regular files]
  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 392 blocks.
  DUMP: Volume 1 started with block 1 at: Tue Mar 12 16:53:41 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /mnt/sdb7/mail.dump.gz
  DUMP: Volume 1 completed at: Tue Mar 12 16:53:41 2013
  DUMP: 410 blocks (0.40MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 0 dump: Tue Mar 12 16:53:40 2013
  DUMP: Date this dump completed:  Tue Mar 12 16:53:41 2013
  DUMP: Average transfer rate: 0 kB/s
  DUMP: Wrote 410kB uncompressed, 34kB compressed, 12.059:1
  DUMP: DUMP IS DONE


==================Sdb7文件系统发生改变

 [root@szm dump]# ll /mnt/sdb7
total 55
drwx------. 2 root root 12288 Mar 12 16:47 lost+found
-rw-r--r--. 1 root root 35657 Mar 12 16:53 mail.dump.gz
drwxr-xr-x. 2 root root  1024 Mar 12 16:48 testdir
drwxr-xr-x. 2 root root  1024 Mar 12 16:57 testdir1
-rw-r--r--. 1 root root     0 Mar 12 16:48 testfile
-rw-r--r--. 1 root root     0 Mar 12 16:58 testfile2
 

 =======================使用Level1级别的Dump

[root@szm dump]# dump -1u -f /mnt/sdb6/level1.dump /mnt/sdb7
  DUMP: Date of this level 1 dump: Tue Mar 12 17:00:08 2013
  DUMP: Date of last level 0 dump: Tue Mar 12 16:48:38 2013
  DUMP: Dumping /dev/sdb7 (/mnt/sdb7) to /mnt/sdb6/level1.dump
  DUMP: Label: none
  DUMP: Writing 10 Kilobyte records
  DUMP: mapping (Pass I) [regular files]

  DUMP: mapping (Pass II) [directories]
  DUMP: estimated 55 blocks.
  DUMP: Volume 1 started with block 1 at: Tue Mar 12 17:00:09 2013
  DUMP: dumping (Pass III) [directories]
  DUMP: dumping (Pass IV) [regular files]
  DUMP: Closing /mnt/sdb6/level1.dump
  DUMP: Volume 1 completed at: Tue Mar 12 17:00:09 2013
  DUMP: Volume 1 60 blocks (0.06MB)
  DUMP: 60 blocks (0.06MB) on 1 volume(s)
  DUMP: finished in less than a second
  DUMP: Date of this level 1 dump: Tue Mar 12 17:00:08 2013
  DUMP: Date this dump completed:  Tue Mar 12 17:00:09 2013
  DUMP: Average transfer rate: 0 kB/s
  DUMP: DUMP IS DONE
 

 [root@szm dump]# ll -h /mnt/sdb6
total 99K
-rw-r--r--. 1 root root  60K Mar 12 17:00 level1.dump
drwx------. 2 root root  12K Mar 12 16:36 lost+found
drwxr-xr-x. 2 root root 1.0K Mar 12 16:55 testdir1
-rw-r--r--. 1 root root    0 Mar 12 16:56 testfile2
-rw-r--r--. 1 root root  20K Mar 12 16:48 test.level1.dump

 [root@szm dump]# cat /etc/dumpdates
/dev/sdb7 0 Tue Mar 12 16:48:38 2013 +0800
/dev/sdb7 1 Tue Mar 12 17:04:02 2013 +0800
 

 [root@szm dump]# dump -W
Last dump(s) done (Dump '>' file systems):
> /dev/mapper/vg_szm-lv_root (     /) Last dump: never
> /dev/sda1 ( /boot) Last dump: never
  /dev/sdb6 (/mnt/sdb6) Last dump: never
  /dev/sdb7 (/mnt/sdb7) Last dump: Level 1, Date Tue Mar 12 17:04:02 2013

 数据恢复工具:restore

[root@szm dump]# restore --help
restore: invalid option -- '-'
restore 0.4b42 (using libext2fs 1.41.12 of 17-May-2010)
usage: restore -C(比较并列出不同的数据) [-cdeHlMvVy] [-b blocksize] [-D filesystem] [-E mls] 
            [-f file] [-F script] [-L limit]  [-s fileno]
 restore -i (目录还原参数,提示用户有选择性地还原特定数据)
[-acdehHlmMouvVy] [-A file] [-b blocksize] [-E mls]
            [-f file] [-F script] [-Q file] [-s fileno]
 restore -P file(从定义好还原内容的文件中提取数据) [-acdhHlmMuvVy] [-b blocksize]
            [-f file] [-F script] [-s fileno] [-X filelist] [file ...]
 restore -r(使用备份数据还原整个文件系统) [-cdeHlMuvVy] [-b blocksize] [-E mls]
            [-f file] [-F script] [-s fileno] [-T directory]
 restore -R(多个文件中还原,支持中断操作) [-cdeHlMuvVy] [-b blocksize] [-E mls]
            [-f file] [-F script] [-s fileno] [-T directory](指定恢复数据的临时目录)
 restore -t(查看备份中有哪些数据) [-cdhHlMuvVy] [-A file] [-b blocksize]
            [-f file] [-F script] [-Q file] [-s fileno] [-X filelist] [file ...]
 restore -x(要恢复数据从媒介中提取) [-acdehHlmMouvVy] [-A file] [-b blocksize] [-E mls]
            [-f file] [-F script] [-Q file] [-s fileno] [-X filelist] [file ...]

 o:无需确认操作自动还原当前目录权限

 [root@szm dump]# restore -t -f /mnt/sdb6/test.level1.dump (查看)
Dump   date: Tue Mar 12 16:48:38 2013
Dumped from: the epoch
Level 0 dump of /mnt/sdb7 on szm:/dev/sdb7
Label: none
         2 .
        11 ./lost+found
      2009 ./testdir
        12 ./testfile

 [root@szm dump]# restore -C -f /mnt/sdb6/test.level1.dump (比较,不同的有显示)
Dump   date: Tue Mar 12 16:48:38 2013
Dumped from: the epoch
Level 0 dump of /mnt/sdb7 on szm:/dev/sdb7
Label: none
filesys = /mnt/sdb7
./testfile: size has changed.
Some files were modified!  1 compare errors
 

[root@szm sdb8]# restore -r -f /mnt/sdb6/test.level1.dump (还原,还原在当前目录)

[root@szm sdb8]# restore -r -f /mnt/sdb6/level1.dump (Level1的还原)

 [root@szm sdb8]# restore -i -f /mnt/sdb6/level1.dump

 数据备份与恢复工具dd:

[root@szm sdb8]# dd --help
Usage: dd [OPERAND]...
  or:  dd OPTION
Copy a file, converting and formatting according to the operands.

  bs=BYTES        read and write BYTES bytes at a time (also see ibs=,obs=)
  cbs=BYTES       convert BYTES bytes at a time
  conv=CONVS      convert the file as per the comma separated symbol list
  count=BLOCKS    copy only BLOCKS input blocks
  ibs=BYTES       read BYTES bytes at a time (default: 512)
  if=FILE         read from FILE instead of stdin
  iflag=FLAGS     read as per the comma separated symbol list
  obs=BYTES       write BYTES bytes at a time (default: 512)
  of=FILE         write to FILE instead of stdout
  oflag=FLAGS     write as per the comma separated symbol list
  seek=BLOCKS     skip BLOCKS obs-sized blocks at start of output
  skip=BLOCKS     skip BLOCKS ibs-sized blocks at start of input
  status=noxfer   suppress transfer statistics

BLOCKS and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.

Each CONV symbol may be:

  ascii     from EBCDIC to ASCII
  ebcdic    from ASCII to EBCDIC
  ibm       from ASCII to alternate EBCDIC
  block     pad newline-terminated records with spaces to cbs-size
  unblock   replace trailing spaces in cbs-size records with newline
  lcase     change upper case to lower case
  nocreat   do not create the output file
  excl      fail if the output file already exists
  notrunc   do not truncate the output file
  ucase     change lower case to upper case
  swab      swap every pair of input bytes
  noerror   continue after read errors
  sync      pad every input block with NULs to ibs-size; when used
            with block or unblock, pad with spaces rather than NULs
  fdatasync  physically write output file data before finishing
  fsync     likewise, but also write metadata

Each FLAG symbol may be:

  append    append mode (makes sense only for output; conv=notrunc suggested)
  direct    use direct I/O for data
  directory  fail unless a directory
  dsync     use synchronized I/O for data
  sync      likewise, but also for metadata
  fullblock  accumulate full blocks of input (iflag only)
  nonblock  use non-blocking I/O
  noatime   do not update access time
  noctty    do not assign controlling terminal from file
  nofollow  do not follow symlinks

Sending a USR1 signal to a running `dd' process makes it
print I/O statistics to standard error and then resume copying.

  $ dd if=/dev/zero of=/dev/null& pid=$!
  $ kill -USR1 $pid; sleep 1; kill $pid
  18335302+0 records in
  18335302+0 records out
  9387674624 bytes (9.4 GB) copied, 34.6279 seconds, 271 MB/s

Options are:

      --help     display this help and exit
      --version  output version information and exit

Report dd bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'dd invocation'
 

==========读取硬盘分区表

[root@szm sdb8]# dd if=/dev/sdb of=/sdb.mbr bs=512 count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000201859 s, 2.5 MB/s
[root@szm sdb8]# file /sdb.mbr
/sdb.mbr: x86 boot sector; partition 1: ID=0x83, starthead 1, startsector 63, 224847 sectors; partition 2: ID=0x8e, starthead 0, startsector 224910, 417690 sectors; partition 3: ID=0x5, starthead 0, startsector 642600, 41287050 sectors, code offset 0x0
 

文件系统监控工具:df/du/gnome-system-monitor

 

[root@szm sdb8]# df --help
Usage: df [OPTION]... [FILE]...
Show information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             include dummy file systems
  -B, --block-size=SIZE  use SIZE-byte blocks-----指定
      --direct          show statistics for a file instead of mount point
      --total           produce a grand total
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si              likewise, but use powers of 1000 not 1024
  -i, --inodes          list inode information instead of block usage
  -k                    like --block-size=1K
  -l, --local           limit listing to local file systems
      --no-sync         do not invoke sync before getting usage info (default)
  -P, --portability     use the POSIX output format
      --sync            invoke sync before getting usage info
  -t, --type=TYPE       limit listing to file systems of type TYPE-----显示指定类型的文件系统
  -T, --print-type      print file system type---------------------------显示文件系统的类型
  -x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
  -v                    (ignored)
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report df bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'df invocation'
 

 

[root@szm sdb8]# du --help
Usage: du [OPTION]... [FILE]...
  or:  du [OPTION]... --files0-from=F
Summarize disk usage of each FILE, recursively for directories.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all             write counts for all files, not just directories
      --apparent-size   print apparent sizes, rather than disk usage; although
                          the apparent size is usually smaller, it may be
                          larger due to holes in (`sparse') files, internal
                          fragmentation, indirect blocks, and the like
  -B, --block-size=SIZE  use SIZE-byte blocks
  -b, --bytes           equivalent to `--apparent-size --block-size=1'
  -c, --total           produce a grand total-----计算文件与目录的统计总数
  -D, --dereference-args  dereference only symlinks that are listed on the
                          command line
      --files0-from=F   summarize disk usage of the NUL-terminated file
                          names specified in file F;
                          If F is - then read names from standard input
  -H                    equivalent to --dereference-args (-D)
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)
      --si              like -h, but use powers of 1000 not 1024
  -k                    like --block-size=1K
  -l, --count-links     count sizes many times if hard linked
  -m                    like --block-size=1M
  -L, --dereference     dereference all symbolic links
  -P, --no-dereference  don't follow any symbolic links (this is the default)
  -0, --null            end each output line with 0 byte rather than newline
  -S, --separate-dirs   do not include size of subdirectories
  -s, --summarize       display only a total for each argument
  -x, --one-file-system    skip directories on different file systems
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE
      --exclude=PATTERN    exclude files that match PATTERN
      --max-depth=N     print the total for a directory (or file, with --all)
                          only if it is N or fewer levels below the command
                          line argument;  --max-depth=0 is the same as
                          --summarize
      --time            show time of the last modification of any file in the
                          directory, or any of its subdirectories
      --time=WORD       show time as WORD instead of modification time:
                          atime, access, use, ctime or status
      --time-style=STYLE  show times using style STYLE:
                          full-iso, long-iso, iso, +FORMAT
                          FORMAT is interpreted like `date'
      --help     display this help and exit
      --version  output version information and exit

Display values are in units of the first available SIZE from --block-size,
and the DU_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.
Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report du bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'du invocation'


[root@szm sdb8]# df -h | grep sd
/dev/sda1             485M   90M  370M  20% /boot
/dev/sdb6              16M  1.3M   14M   9% /mnt/sdb6
/dev/sdb7              16M  1.2M   14M   9% /mnt/sdb7
/dev/sdb8              16M  1.2M   14M   9% /mnt/sdb8
 

[root@szm sdb8]# df -H -h -T | grep sd(1000)
/dev/sda1     ext4    485M   90M  370M  20% /boot
/dev/sdb6     ext3     16M  1.3M   14M   9% /mnt/sdb6
/dev/sdb7     ext3     16M  1.2M   14M   9% /mnt/sdb7
/dev/sdb8     ext3     16M  1.2M   14M   9% /mnt/sdb8
 

[root@szm sdb8]# df -a -H -h -T(所有)
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_szm-lv_root
              ext4     18G  7.4G  9.3G  45% /
proc          proc       0     0     0   -  /proc
sysfs        sysfs       0     0     0   -  /sys
devpts      devpts       0     0     0   -  /dev/pts
tmpfs        tmpfs    250M  228K  250M   1% /dev/shm
/dev/sda1     ext4    485M   90M  370M  20% /boot
none   binfmt_misc       0     0     0   -  /proc/sys/fs/binfmt_misc
.host:/     vmhgfs    102G  101G  1.7G  99% /mnt/hgfs
vmware-vmblock
fuse.vmware-vmblock       0     0     0   -  /var/run/vmblock-fuse
sunrpc  rpc_pipefs       0     0     0   -  /var/lib/nfs/rpc_pipefs
/dev/sdb6     ext3     16M  1.3M   14M   9% /mnt/sdb6
/dev/sdb7     ext3     16M  1.2M   14M   9% /mnt/sdb7
/dev/sdb8     ext3     16M  1.2M   14M   9% /mnt/sdb8
 

[root@szm sdb8]# du -h /mnt/sdb7
2.0K /mnt/sdb7/testdir
2.0K /mnt/sdb7/testdir1
12K /mnt/sdb7/lost+found
58K /mnt/sdb7