學習筆記一:壓縮 學習筆記一:壓縮 2015年2月5日 上午 10:23 2015年2月5日 上午 10:23 壓縮命令 壓縮文件的擴展名大多是*.tar、*.tar.gz、*.tgz、*.gz、*.Z、*.bz2 常見的壓縮命令gzip與bzip2,其中bzip2壓縮比gzip要好 tar可以用來 ...
學習筆記一:壓縮 2015年2月5日 上午 10:23 壓縮命令 壓縮文件的擴展名大多是*.tar、*.tar.gz、*.tgz、*.gz、*.Z、*.bz2 常見的壓縮命令gzip與bzip2,其中bzip2壓縮比gzip要好 tar可以用來進行文件打包,並可支持gzip和bzip2的壓縮 壓縮 tar -jvc -f filename.tar.bz2 /directory 查詢 tar -jtv -f filename.tar.bz2 解壓 tar -jxv -f filename.tar.bz2 -C /puorose/directory Dump 命令可備份文件系統或單一目錄 Dump 的備份若針對文件系統時,可進行0~9的level差異備份。其中level為0為完整備份 restore命令可以還原被dump構建的備份文件 要新建光碟刻錄數據時,可通過mkisofs命令來構建 可通過cdrecord來寫入CD或DVD刻錄機 dd可備份完整的分區或磁碟,因為dd可讀取硬碟的扇區錶面數據 cpio為相當優秀的備份命令,不過必須要搭配類似find命令來讀入預備份文件 測試演練 gzip與bzip2壓縮 tar打包 使用gzip壓縮格式並且排除log和bz壓縮檔 [oracle@xitest01 schema]$ tar -zcv -f schema_tar_test.tar.gz --exclude=/u03/schema/*.log --exclude=/u03/schema/*.bz /u03/schema 使用bzip2壓縮格式並且排除log和gz壓縮檔 [oracle@xitest01 schema]$ tar -jcv -f schema_tar_test.tar.bz2 --exclude=/u03/schema/*.log --exclude=/u03/schema/*.gz /u03/schema 查看兩者壓縮比例 [oracle@xitest01 schema]$ du -sh schema_tar_test.tar.* 160K schema_tar_test.tar.bz2 260K schema_tar_test.tar.gz dump備份文件系統 模擬一個文件盤符 [root@xitest01 u04]# dd if=/dev/zero of=/u04/loop_mount bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 8.35942 seconds, 128 MB/s [root@xitest01 u04]# mkfs.ext3 /u04/loop_mount [root@xitest01 u04]# mount -o loop /u04/loop_mount /u04/mount_loop [root@xitest01 u04]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 9.7G 5.4G 3.9G 59% / /dev/sda6 31G 1.9G 28G 7% /u02 /dev/sda5 30G 21G 7.1G 75% /u01 /dev/sda1 190M 23M 158M 13% /boot tmpfs 1005M 0 1005M 0% /dev/shm /dev/sdb 504G 263G 216G 55% /u03 /dev/sdc1 504G 312G 167G 66% /u04 /u04/loop_mount 1008M 34M 924M 4% /u04/mount_loop 創建dump備份目錄 [root@xitest01 u04]# mkdir backup [root@xitest01 u04]# dump -0 -j -f /u04/backup/dump.bak /u04/loop_mount DUMP: Dumping /dev/sdc1 (/u04 (dir /loop_mount)) to /u04/backup/dump.bak 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 1067027 blocks. DUMP: Volume 1 started with block 1 at: Thu Feb 5 10:08:25 2015 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing /u04/backup/dump.bak DUMP: Volume 1 completed at: Thu Feb 5 10:09:01 2015 DUMP: Volume 1 took 0:00:36 DUMP: Volume 1 transfer rate: 156 kB/s DUMP: Volume 1 1067020kB uncompressed, 5627kB compressed, 189.626:1 DUMP: 1067020 blocks (1042.01MB) on 1 volume(s) DUMP: finished in 36 seconds, throughput 29639 kBytes/sec DUMP: Date of this level 0 dump: Thu Feb 5 10:08:25 2015 DUMP: Date this dump completed: Thu Feb 5 10:09:01 2015 DUMP: Average transfer rate: 156 kB/s DUMP: Wrote 1067020kB uncompressed, 5627kB compressed, 189.626:1 DUMP: DUMP IS DONE [root@xitest01 u04]# ls -l /u04/backup/ total 5640 -rw-r--r-- 1 root root 5762814 Feb 5 10:09 dump.bak [root@xitest01 u04]# du -sh /u04/backup/ 5.6M /u04/backup/ 測試加入文件至目錄 [root@xitest01 u04]# cp ogg.tar.gz /u04/mount_loop/ [root@xitest01 u04]# du -sh /u04/mount_loop/ 503M /u04/mount_loop/ [root@xitest01 u04]# dump -1 -j -f /u04/backup/dump.bak /u04/loop_mount DUMP: Only level 0 dumps are allowed on a subdirectory (不是單一文件系統) DUMP: The ENTIRE dump is aborted. 備份boot盤符測試 [root@xitest01 u04]# dump -0 -j -f /u04/backup/dump_boot.bak /dev/sda1 [root@xitest01 u04]# dump -1 -j -f /u04/backup/dump_boo01.bak /dev/sda1 DUMP: WARNING: There is no inferior level dump on this filesystem DUMP: WARNING: Assuming a level 0 dump by default (boot目錄也沒差異備份嗎?) [root@xitest01 u04]# cd /u04/backup/ [root@xitest01 backup]# ls dump.bak dump_boo01.bak dump_boot.bak [root@xitest01 backup]# du -sh * 5.6M dump.bak 16M dump_boo01.bak 16M dump_boot.bak
Database | Ip | Gzip | Bzip2 | ||
xxxxx | xxx.xxx.xxx.xxx | 2015/3/22 10:22:00 ~2015/3/23 01:5600 3小時 | 16GB | 2015/03/25 09:05~2015/03/26 00:56 16小時 | 9.2GB |