Common backup Linux backup tools – 1

1. CPIO

Full backup:

[root@localhost /]# find /home/ -print | cpio -oF /root/backup/cpiofull
11 blocks

Incremental backup 1:

[root@localhost /]# touch /home/newfile1 /home/newfile2
[root@localhost /]# find /home/ -cnewer /root/backup/cpiofull -print
/home/newfile1
/home/newfile2
[root@localhost /]# find /home/ -cnewer /root/backup/cpiofull -print | cpio -oF /root/backup/cpioinc1
4 blocks

Incremental backup 2:

[root@localhost /]# touch /home/newfile3
[root@localhost /]# touch /home/newfile4
[root@localhost /]# find /home/ -cnewer /root/backup/cpioinc1 -print
/home/newfile4
/home/newfile3
[root@localhost /]# find /home/ -cnewer /root/backup/cpioinc1 -print | cpio -oF /root/backup/cpioinc2
4 blocks

And so on for next incremental backups.

Check our backup files:

[root@localhost /]# cpio -tF /root/backup/cpioinc1 2>/dev/null
home/
home/newfile1
home/newfile2
[root@localhost /]# cpio -tF /root/backup/cpioinc2 2>/dev/null
home/
home/newfile4
home/newfile3

Restore:

Restore Full backup:

[root@localhost /]# rm -rf /home/*
[root@localhost /]# ls /home/
[root@localhost /]# cd /
[root@localhost /]# cpio -iF /root/backup/cpiofull 2>/dev/null
[root@localhost /]# ls home/
user1  user2  user3  user4  users

Restore Incremental backup 1:

[root@localhost /]# cpio -iF /root/backup/cpioinc1 2>/dev/null
[root@localhost /]# ls /home/
newfile1  newfile2  user1  user2  user3  user4  users

Restore Incremental backup 2:

[root@localhost /]# cpio -iF /root/backup/cpioinc2 2>/dev/null
[root@localhost /]# ls home/
newfile1  newfile2  newfile3  newfile4  user1  user2  user3  user4  users

Done.

2. PAX

Create full backup

[root@localhost ~]# pax -wf /root/backup/$(date +%d%m%Y) /home/
[root@localhost ~]# ls -alh /root/backup/
total 200K
drwxr-xr-x  3 root root 4.0K Jan 29 00:59 .
drwxr-x— 20 root root 4.0K Jan 29 00:17 ..
-rw-r–r–  1 root root  40K Jan 29 00:59 29012012
-rw-r–r–  1 root root 5.5K Jan 29 00:42 cpiofull
-rw-r–r–  1 root root  512 Jan 29 00:43 cpioinc1
-rw-r–r–  1 root root  512 Jan 29 00:44 cpioinc2
drwxr-xr-x  7 root root 4.0K Jan 29 00:29 home
-rw-r–r–  1 root root  40K Jan 27 05:21 paxbackup
-rw-r–r–  1 root root  10K Jan 28 00:00 Sat
-rw-r–r–  1 root root  40K Jan 28 00:00 Sat1

Create Incremential backup 1. We’ve done the full backup for the date “29 Jan” so next we will do incremental backup for “30 Jan”. Just set the date to what we want.

[root@localhost ~]# date
Sun Jan 29 00:59:56 ICT 2012

[root@localhost ~]# date -s “30 Jan 2012”

Mon Jan 30 00:00:00 ICT 2012
[root@localhost ~]# touch /home/newfile1 /home/newfile2
[root@localhost ~]# pax -T 0000 -wf /root/backup/$(date +%d%m%Y) /home
[root@localhost ~]# ls -alh /root/backup/
total 104K
drwxr-xr-x  2 root root 4.0K Jan 30 00:04 .
drwxr-x— 20 root root 4.0K Jan 29 00:17 ..
-rw-r–r–  1 root root  40K Jan 29 00:59 29012012
-rw-r–r–  1 root root  10K Jan 30 00:01 30012012
-rw-r–r–  1 root root 5.5K Jan 29 00:42 cpiofull
-rw-r–r–  1 root root  512 Jan 29 00:43 cpioinc1
-rw-r–r–  1 root root  512 Jan 29 00:44 cpioinc2

Create Incremential backup 2 for 31 Jan.

[root@localhost ~]# date
Mon Jan 30 00:07:18 ICT 2012
[root@localhost ~]# date -s “31 Jan 2012”
Tue Jan 31 00:00:00 ICT 2012
[root@localhost ~]# touch /home/
newfile1  newfile2  user1/    user2/    user3/    user4/    users/
[root@localhost ~]# touch /home/newfile3
[root@localhost ~]# echo “newline” >> /home/newfile1
[root@localhost ~]# pax -T 0000 -wf /root/backup/$(date +%d%m%Y) /home/
[root@localhost ~]# ls -alh /root/backup/
total 120K
drwxr-xr-x  2 root root 4.0K Jan 31 00:01 .
drwxr-x— 20 root root 4.0K Jan 29 00:17 ..
-rw-r–r–  1 root root  40K Jan 29 00:59 29012012
-rw-r–r–  1 root root  10K Jan 30 00:01 30012012
-rw-r–r–  1 root root  10K Jan 31 00:01 31012012
-rw-r–r–  1 root root 5.5K Jan 29 00:42 cpiofull
-rw-r–r–  1 root root  512 Jan 29 00:43 cpioinc1
-rw-r–r–  1 root root  512 Jan 29 00:44 cpioinc2

Restore. We follow the backup order respectedly.

[root@centos ~]# rm -rf /home/*
[root@centos ~]# pax -rf /root/backup/29012012
[root@centos ~]# ls /home/
user1 user2 user3 user4 users

[root@centos ~]# pax -rf /root/backup/30012012
[root@centos ~]# ls /home/
newfile1 newfile2 user1 user2 user3 user4 users
[root@centos ~]# cat /home/newfile1

[root@centos ~]# pax -rf /root/backup/31012012
[root@centos ~]# ls /home/
newfile1 newfile2 newfile3 user1 user2 user3 user4 users
[root@centos ~]# cat /home/newfile1
newline

Done.

This lab is done on:

[root@centos ~]# lsb_release -a | grep Description ; echo “Linux kernel: `uname -r`”
Description: CentOS release 5.7 (Final)
Linux kernel: 2.6.18-274.18.1.el5

dongthao

About dongthao

The best things in life, they are free ... (Cry on my shoulder lyric)
This entry was posted in Linux, Linux Servers, Linux Tutorial and tagged , , , , . Bookmark the permalink.

Gửi phản hồi

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Log Out / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Log Out / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Log Out / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Log Out / Thay đổi )

Connecting to %s