Kiedyś napisałem programik w /bin/sh do tworzenia kopii plików, katalogów oraz surowych partycji.
Jako mały trening przeportowałem go na Solaris, jednak nie próbowałem go jeszcze uruchamiać na innych systemach, więc mogą i pewnie są jeszcze gdzieś BUGi.
Podam mały przykład jak zrobić kopię pliku (to może być również dysk, partycja, itp).
pbackup w trybie 'RAW' tnie plik źródłowy na 100MB kawałki, kompresuje je, robi sumy kontrolne i zapisuje informacje do logów.
Zrobimy kopię pliku 'source.raw', zamiast pliku to może być partycja lub cały dysk.
-bash-3.2$ ls -lh
total 66
-rw-r--r-- 1 pbackup-usr other 1,0K cz 3 20:30 local.cshrc
-rw-r--r-- 1 pbackup-usr other 1002 cz 3 20:30 local.login
-rw-r--r-- 1 pbackup-usr other 1019 cz 3 20:30 local.profile
-rwxr-xr-x 1 pbackup-usr root 23K cz 3 22:58 pbackup
-rwxr-xr-x 1 pbackup-usr root 1,5K cz 3 20:30 pbackup_cut
-rwxr-xr-x 1 pbackup-usr root 1,7K cz 3 23:12 pbackup_raw_restore
-rwxr-xr-x 1 pbackup-usr other 23K cz 3 22:29 pbackup_v3.4
-rw------- 1 pbackup-usr other 400M cz 3 22:44 source.raw
-bash-3.2$ ./pbackup -r -M -c /export/home/pbackup-usr/my_backup -T /export/home/pbackup-usr/source.raw
pbackup version current
new backup directory: /export/home/pbackup-usr/my_backup/2008_06_03__23-13_52-full
Date of backup: 2008_06_03__23-13_52
##################################################
Use suffix: *.tar.gz
##################################################
Raw partitions:
Using file /export/home/pbackup-usr/my_backup/2008_06_03__23-13_52-full/__tmp_raw
raw_bs=1000000 raw_count=100
*** partition: /export/home/pbackup-usr/source.raw => raw____export___home___pbackup-usr___source.raw
status: 1 - copying, 2 - compressing, 3 - checking
raw____export___home___pbackup-usr___source.raw
skip: 0 file: raw____export___home___pbackup-usr___source.raw.1000 1 2 3 md5 ... ok
skip: 100 file: raw____export___home___pbackup-usr___source.raw.1001 1 2 3 md5 ... ok
skip: 200 file: raw____export___home___pbackup-usr___source.raw.1002 1 2 3 md5 ... ok
skip: 300 file: raw____export___home___pbackup-usr___source.raw.1003 1 2 3 md5 ... ok
skip: 400 file: raw____export___home___pbackup-usr___source.raw.1004 1 2 3 md5 ... ok
Compressing /export/home/pbackup-usr/my_backup/2008_06_03__23-13_52-full/log ... ok
Done
-bash-3.2$
Tak wygląda kopia:
-bash-3.2$ ls -alh my_backup/
total 25
drwxr-x--- 3 pbackup-usr other 3 cz 3 23:13 .
drwx------ 3 pbackup-usr other 13 cz 3 23:13 ..
drwxr-x--- 2 pbackup-usr other 13 cz 3 23:14 2008_06_03__23-13_52-full
-bash-3.2$ ls -alh my_backup/2008_06_03__23-13_52-full/
total 68
-rw-r----- 1 pbackup-usr other 36 cz 3 23:13 __tmp_raw
drwxr-x--- 2 pbackup-usr other 13 cz 3 23:14 .
drwxr-x--- 3 pbackup-usr other 3 cz 3 23:13 ..
-rw-r----- 1 pbackup-usr other 0 cz 3 23:14 .all_done
-rw-r----- 1 pbackup-usr other 9 cz 3 23:13 date
-rw-r----- 1 pbackup-usr other 371 cz 3 23:14 log.gz
-rw-r----- 1 pbackup-usr other 372 cz 3 23:14 log~.gz
-rw-r----- 1 pbackup-usr other 95K cz 3 23:13 raw____export___home___pbackup-usr___source.raw.1000.gz
-rw-r----- 1 pbackup-usr other 95K cz 3 23:13 raw____export___home___pbackup-usr___source.raw.1001.gz
-rw-r----- 1 pbackup-usr other 95K cz 3 23:14 raw____export___home___pbackup-usr___source.raw.1002.gz
-rw-r----- 1 pbackup-usr other 95K cz 3 23:14 raw____export___home___pbackup-usr___source.raw.1003.gz
-rw-r----- 1 pbackup-usr other 18K cz 3 23:14 raw____export___home___pbackup-usr___source.raw.1004.gz
-rw-r----- 1 pbackup-usr other 450 cz 3 23:14 raw.md5
-bash-3.2$
Teraz przywrócimy kopię w inne miejsce.
Na początku pbackup sprawdza sumy kontrolne kopii, dopiero potem przywraca dane:
-bash-3.2$ ./pbackup_raw_restore my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw my_restored
pbackup_raw_restore version 0.3
source=my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw
destination=my_restored
Checking source:
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1000.gz ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1001.gz ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1002.gz ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1003.gz ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1004.gz ... ok
DD_RAW_BS=1000000 DD_RAW_COUNT=100
Restoring my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.* to my_restored ...
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1000.gz seek: 0 ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1001.gz seek: 100 ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1002.gz seek: 200 ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1003.gz seek: 300 ... ok
my_backup/2008_06_03__23-13_52-full/raw____export___home___pbackup-usr___source.raw.1004.gz seek: 400 ... ok
ok
-bash-3.2$ ls -lh
total 70
-rw-r--r-- 1 pbackup-usr other 1,0K cz 3 20:30 local.cshrc
-rw-r--r-- 1 pbackup-usr other 1002 cz 3 20:30 local.login
-rw-r--r-- 1 pbackup-usr other 1019 cz 3 20:30 local.profile
drwxr-x--- 3 pbackup-usr other 3 cz 3 23:13 my_backup
-rw-r--r-- 1 pbackup-usr other 400M cz 3 23:18 my_restored
-rwxr-xr-x 1 pbackup-usr root 23K cz 3 22:58 pbackup
-rwxr-xr-x 1 pbackup-usr root 1,5K cz 3 20:30 pbackup_cut
-rwxr-xr-x 1 pbackup-usr root 1,7K cz 3 23:12 pbackup_raw_restore
-rwxr-xr-x 1 pbackup-usr other 23K cz 3 22:29 pbackup_v3.4
-rw------- 1 pbackup-usr other 400M cz 3 22:44 source.raw
-bash-3.2$
Pliki są identyczne:
-bash-3.2$ cmp source.raw my_restored
-bash-3.2$
Pbackup wyświetla ustawione zmienne:
-bash-3.2$ ./pbackup -H
pbackup version current
Variables:
DIR_NEW_BACKUP=2008_06_03__23-19_24
DIR_BACKUP=/home/BACKUP
DIR_BR=
DIR_RAW=
DIR_DIRS=
FILE_MD5=md5
FILE_LOG=log
FILE_DIRS=/export/home/pbackup-usr/.pbackup_dirs
FILE_DIRS_EXCLUDE=/export/home/pbackup-usr/.pbackup_dirs_exclude
FILE_BR=/export/home/pbackup-usr/.pbackup_br
FILE_RAW=/export/home/pbackup-usr/.pbackup_raw
FILE_BACKUP_TYPE=dirs_type
FILE_TMP_LOG=__tmp_log
FILE_TMP_DIRS=__tmp_dirs
FILE_TMP_DIRS_EXCLUDE=__tmp_dirs_exclude
FILE_TMP_BR=__tmp_br
FILE_TMP_RAW=__tmp_raw
DEBUG=NO
VERBOSE=NO
BACKUP_DIRS=YES
BACKUP_BR=NO
BACKUP_RAW=NO
USE_BZIP2=NO
USE_DIRS_EXCLUDE=NO
SHOW_DIRS_EXCLUDE=YES
SHOW_FIND_LAST=YES
DD_BR_BS=1000
DD_BR_COUNT=64
DD_RAW_BS=1000000
DD_RAW_COUNT=100
UMASK=0027
INCR_LAST=NO
INCR_NEWER=NO
-bash-3.2$
Oraz wszystkie dostępne parametry:
-bash-3.2$ ./pbackup -h
pbackup version current
Usage: ./pbackup [OPTIONS]
OPTIONS:
-a backup type = full
-b use bzip2
-B use gzip
-c /my_backup set DIR_BACKUP
-C new_backup set DIR_NEW_BACKUP
-d my_file_dirs.txt set FILE_DIRS
-D "~/bin /opt" list of directories
-e dirs_exclude.txt path to FILE_DIRS_EXCLUDE
-E "*.old" exclude from backup
-g DEBUG=YES
-G DEBUG=NO
-h show help
-H show variables
-m BACKUP_DIRS=YES
-M BACKUP_DIRS=NO
-n 20050720 incremental, newer than 2005-07-20
-N 5 incremental, last 5 days
With this option, exclude file doesn't work!!!
-p br.txt path to FILE_BR
-P "/dev/hda /dev/hdb" list of boot records
-q quiet
-r BACKUP_RAW=YES
-R BACKUP_RAW=NO
-s BACKUP_BR=YES
-S BACKUP_BR=NO
-t my_partitions.txt path to FILE_RAW
-T "/dev/hda4 /dev/hdb2" list of partitions
-v verbose
-V show version
-x USE_DIRS_EXCLUDE=YES
-X USE_DIRS_EXCLUDE=NO
-y SHOW_DIRS_EXCLUDE=YES
-Y SHOW_DIRS_EXCLUDE=NO
-z SHOW_FIND_LAST=YES
-Z SHOW_FIND_LAST=NO
license: CDDL
author: Piotr Jasiukajtis / estibi
-bash-3.2$
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz