Quantcast
Viewing latest article 2
Browse Latest Browse All 18

tar and ssh – make a backup

In this example we're using tar and ssh to make a backup of just a directory over the network. The directory 'sampledir/' from the node SLES11FT will be compressed and stored on the node LXSWAS01 into the directory '/tmp' named as 'lxfiles.tgz'.

SLES11FT (10.199.10.50)                                                        LXSWAS01 (10.199.10.59)
/home/daniel/sampledir                                                              /tmp
.. ..
doc1.txt     \                                                                               lxfiles.tgz
doc2.txt       \
doc3.txt      /
doc4.txt   /
daniel@SLES11FT:~/sampledir> ls
doc1.txt doc2.txt doc3.txt doc4.txt
daniel@SLES11FT:~/sampledir> tar czfv - /home/daniel/sampledir/ | ssh root@10.199.10.59 "cat > /tmp/lxfiles.tgz"
tar: Removing leading `/' from member names
/home/daniel/sampledir/
/home/daniel/sampledir/doc4.txt
/home/daniel/sampledir/doc3.txt
/home/daniel/sampledir/doc2.txt
/home/daniel/sampledir/doc1.txt
Password:
daniel@SLES11FT:~/sampledir>

To show the content of the compressed file, "watch" tv, means use the option tvzf.

LXSWAS01:/tmp # tar tvzf lxfiles.tgz
drwxr-xr-x daniel/users 0 2013-02-05 13:11 home/daniel/sampledir/
-rw-r--r-- daniel/users 592 2013-02-05 13:11 home/daniel/sampledir/doc4.txt
-rw-r--r-- daniel/users 592 2013-02-05 07:08 home/daniel/sampledir/doc3.txt
-rw-r--r-- daniel/users 592 2013-02-05 07:07 home/daniel/sampledir/doc2.txt
-rw-r--r-- daniel/users 592 2013-02-05 07:07 home/daniel/sampledir/doc1.txt

We're going to delete the files within sampledir.

daniel@SLES11FT:~/sampledir> rm *
daniel@SLES11FT:~/sampledir> ls
daniel@SLES11FT:~/sampledir>

To restore the files, we're establishing an ssh connection and get back the files with the options '-C' (directory) and '-x' (extract).

daniel@SLES11FT:~/sampledir> ssh root@10.199.10.59 "cat /tmp/lxfiles.tgz" | tar -C / -xvz
Password:
home/daniel/sampledir/
home/daniel/sampledir/doc4.txt
home/daniel/sampledir/doc3.txt
home/daniel/sampledir/doc2.txt
home/daniel/sampledir/doc1.txt
daniel@SLES11FT:~/sampledir> ls
doc1.txt doc2.txt doc3.txt doc4.txt
daniel@SLES11FT:~/sampledir>

The post tar and ssh – make a backup appeared first on Linux on the mainframe.


Viewing latest article 2
Browse Latest Browse All 18

Trending Articles