http://www.linuxserverworldadmin.blogspot.in/2015/03/different-types-of-backup-in-linux.html
Backups
Create a folder
[root@client24 ~]# cd /myfolder/
[root@client24 myfolder]# mkdir dir1
[root@client24 myfolder]#touch 1 test_file tom_file
[root@client24 myfolder]# ls
1 dir1 test_file tom_file
tar: Removing leading `/' from member names /myfolder/
/myfolder/dir1/
/myfolder/tom_file /myfolder/test_file /myfolder/1
[root@client24 ~]# ls -ld myfolder.tar
-rw-r--r-- 1 root root 10240 Jul 13 03:07 myfolder.tar
To zip the tar file.
[root@client24 ~]# gzip myfolder.tar
[root@client24 ~]# ls -ld myfolder.tar.gz
-rw-r--r-- 1 root root 264 Jul 13 03:07 myfolder.tar.gz
To unzip the tar file
[root@client24 ~]# gunzip myfolder.tar.gz
[root@client24 ~]# ls -ld myfolder.tar
-rw-r--r-- 1 root root 10240 Jul 13 03:07 myfolder.tar
[root@client24 ~]# rm myfolder.tar
rm: remove regular file `myfolder.tar'? y
To create a tar file with zip
[root@client24 ~]# tar -cvzf myfolder.tz /myfolder
tar: Removing leading `/' from member names /myfolder/
/myfolder/dir1/
/myfolder/tom_file /myfolder/test_file /myfolder/1
[root@client24 ~]# ls -ld myfolder.tz
-rw-r--r-- 1 root root 251 Jul 13 03:09 myfolder.tz
To view the contents of the tar file without extracting.
[root@client24 ~]# tar -tvzf myfolder.tz
drwxrwxrwx root/root
drwxr-xr-x root/root
-rw-r--r-- tom/joy
-rw-rw-rw- root/root
-rw-r--r-- tom/joy
0 2008-07-13 01:31:34 myfolder/
0 2008-07-13 01:28:39 myfolder/dir1/
12 2008-07-13 01:29:51 myfolder/tom_file
0 2008-07-13 00:06:35 myfolder/test_file
0 2008-07-13 01:31:34 myfolder/1
[root@client24 ~]# rm -r /myfolder
rm: descend into directory `/myfolder'? y
rm: remove directory `/myfolder/dir1'? y
rm: remove regular file `/myfolder/tom_file'? y
rm: remove regular empty file `/myfolder/test_file'? y rm: remove regular empty file `/myfolder/1'? y
rm: remove directory `/myfolder'? y
[root@client24 ~]# cd /
myfolder/dir1/
myfolder/tom_file myfolder/test_file myfolder/1
[root@client24 /]# ls -ld myfolder
drwxrwxrwx 3 root root 4096 Jul 13 01:31 myfolder
[root@client24 /]# ls /myfolder/
1 dir1 test_file tom_file
[root@client24 ~]# cd /myfolder/
To copy files to archive.
[root@client24 myfolder]# ls | cpio -ov > myfolder.cpio
1
dir1
myfolder.cpio
test_file
tom_file
1 block
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file [root@client24 myfolder]# rm -r *
rm: remove regular empty file `1'? y rm: remove directory `dir1'? y
rm: remove regular file `myfolder.cpio'? n
rm: remove regular empty file `test_file'? y rm: remove regular file `tom_file'? y
1
dir1
cpio: myfolder.cpio not created: newer or same age version exists myfolder.cpio
test_file
tom_file
1 block
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file
[root@client24 ~]# cat > test
test file for scp
root@192.168.0.23's password:
test
100% 18 0.0KB/s 00:00
[root@client24 ~]# rm test
rm: remove regular file `test'? y
root@192.168.0.23's password:
test
100% 18 0.0KB/s 00:00
[root@client24 ~]# ls -ld test
-rw-r--r-- 1 root root 18 Jul 13 03:27 test
Backups
Create a folder
[root@client24 ~]# cd /myfolder/
[root@client24 myfolder]# mkdir dir1
[root@client24 myfolder]#touch 1 test_file tom_file
[root@client24 myfolder]# ls
1 dir1 test_file tom_file
Use the tar command to tape archive the folder.
[root@client24 ~]# tar -cvf myfolder.tar /myfoldertar: Removing leading `/' from member names /myfolder/
/myfolder/dir1/
/myfolder/tom_file /myfolder/test_file /myfolder/1
[root@client24 ~]# ls -ld myfolder.tar
-rw-r--r-- 1 root root 10240 Jul 13 03:07 myfolder.tar
To zip the tar file.
[root@client24 ~]# gzip myfolder.tar
[root@client24 ~]# ls -ld myfolder.tar.gz
-rw-r--r-- 1 root root 264 Jul 13 03:07 myfolder.tar.gz
To unzip the tar file
[root@client24 ~]# gunzip myfolder.tar.gz
[root@client24 ~]# ls -ld myfolder.tar
-rw-r--r-- 1 root root 10240 Jul 13 03:07 myfolder.tar
[root@client24 ~]# rm myfolder.tar
rm: remove regular file `myfolder.tar'? y
To create a tar file with zip
[root@client24 ~]# tar -cvzf myfolder.tz /myfolder
tar: Removing leading `/' from member names /myfolder/
/myfolder/dir1/
/myfolder/tom_file /myfolder/test_file /myfolder/1
[root@client24 ~]# ls -ld myfolder.tz
-rw-r--r-- 1 root root 251 Jul 13 03:09 myfolder.tz
To view the contents of the tar file without extracting.
[root@client24 ~]# tar -tvzf myfolder.tz
drwxrwxrwx root/root
drwxr-xr-x root/root
-rw-r--r-- tom/joy
-rw-rw-rw- root/root
-rw-r--r-- tom/joy
0 2008-07-13 01:31:34 myfolder/
0 2008-07-13 01:28:39 myfolder/dir1/
12 2008-07-13 01:29:51 myfolder/tom_file
0 2008-07-13 00:06:35 myfolder/test_file
0 2008-07-13 01:31:34 myfolder/1
[root@client24 ~]# rm -r /myfolder
rm: descend into directory `/myfolder'? y
rm: remove directory `/myfolder/dir1'? y
rm: remove regular file `/myfolder/tom_file'? y
rm: remove regular empty file `/myfolder/test_file'? y rm: remove regular empty file `/myfolder/1'? y
rm: remove directory `/myfolder'? y
[root@client24 ~]# cd /
To extract the tar file.
[root@client24 /]# tar -xvzf /root/myfolder.tz myfolder/myfolder/dir1/
myfolder/tom_file myfolder/test_file myfolder/1
[root@client24 /]# ls -ld myfolder
drwxrwxrwx 3 root root 4096 Jul 13 01:31 myfolder
[root@client24 /]# ls /myfolder/
1 dir1 test_file tom_file
[root@client24 ~]# cd /myfolder/
To copy files to archive.
[root@client24 myfolder]# ls | cpio -ov > myfolder.cpio
1
dir1
myfolder.cpio
test_file
tom_file
1 block
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file [root@client24 myfolder]# rm -r *
rm: remove regular empty file `1'? y rm: remove directory `dir1'? y
rm: remove regular file `myfolder.cpio'? n
rm: remove regular empty file `test_file'? y rm: remove regular file `tom_file'? y
To copy files from archive.
[root@client24 myfolder]# cpio -iv < myfolder.cpio1
dir1
cpio: myfolder.cpio not created: newer or same age version exists myfolder.cpio
test_file
tom_file
1 block
[root@client24 myfolder]# ls
1 dir1 myfolder.cpio test_file tom_file
[root@client24 ~]# cat > test
test file for scp
Copy the test file to a remote systems /root directory
[root@client24 ~]# scp -r test 192.168.0.23:/root/root@192.168.0.23's password:
test
100% 18 0.0KB/s 00:00
[root@client24 ~]# rm test
rm: remove regular file `test'? y
Copy the file on a remote systems to the /root/test directory
[root@client24 ~]# scp -r 192.168.0.23:/root/test .root@192.168.0.23's password:
test
100% 18 0.0KB/s 00:00
[root@client24 ~]# ls -ld test
-rw-r--r-- 1 root root 18 Jul 13 03:27 test
No comments:
Post a Comment