09 Backup and Restore

Ruatja dhe rikthimi i te dhenave

Per te ruajtur te dhenat ne redhat ka disa mjete te cilat jane te pershtatura per skenare te ndryshem. Nder keto mjete do te permendnim dump(restore), tar dhe cpio.

Komanda dump mund te beje backup te te dhenave te nje volumi ose te nje direktorie te percaktuar. Ajo eshte e pershtatur me shume per te bere backup te nje volumi te tere, ndersa komandat tar dhe cpio jane me te pershtatshme per te arkivuar nje peme direktorish.

Komanda dump ruan te dhenat ne skedare te backup te cilet perdoren me pas nga komanda restore per te rikthyer te dhenat.

Instalimi i dump

[student@localhost ~]$ yum install dump*

| 17 kB 00:00

(3/3): rmt-0.4-0.6.b42.el6.i686.rpm | 25 kB 00:00

------------------------------------------------.....

Complete!

[root@localhost student]# dump

dump 0.4b42 (using libext2fs 1.41.12 of 17-May-2010)

usage: dump [-level#] [-acmMnqSuv] [-A file] [-B records] [-b blocksize]

[-d density] [-D file] [-e inode#,inode#,...] [-E file]

[-f file] [-h level] [-I nr errors] [-j zlevel] [-Q file]

[-s feet] [-T date] [-y] [-z zlevel] filesystem

dump [-W | -w]

[root@localhost student]#

komada dump , mund te marre disa argumenta qe percaktojne sjelljen e saj.

Disa nga keto argumenta jane:

- niveli i backupit ( nje vlere numerike nga 0 deri ne 9)

- skedari ku do te ruhet backup ( -f )

- nje flag (-u) qe percakton nese do te updatohet apo jo skedari ne te cilin ruhet historiku i komandave dump ( Historiku i komandave dump ruhet ne skedarin /etc/dumpdates)

- Nje label qe percakton emertimin e backup-it ( -L emri)

- Nivelin e kompresimit te backup-it ( -z)

Perdorimi i komandes dump per te bere backup nje volum te tere:

Shembulli me poshte ruan ne nje skedar /root/backups/home.bck nje backup te dosjes /home/

[root@localhost restores]# dump -0 -u -z -L homebackup -f /root/backups/home.bck /home/

DUMP: Date of this level 0 dump: Thu Dec 12 02:10:15 2013

DUMP: Dumping /dev/sda5 (/home) to /root/backups/home.bck

DUMP: Label: homebackup

DUMP: Writing 10 Kilobyte records

DUMP: Compressing output at compression level 2 (zlib)

DUMP: mapping (Pass I) [regular files]

DUMP: mapping (Pass II) [directories]

DUMP: estimated 23245 blocks.

DUMP: Volume 1 started with block 1 at: Thu Dec 12 02:10:15 2013

DUMP: dumping (Pass III) [directories]

DUMP: dumping (Pass IV) [regular files]

DUMP: Closing /root/backups/home.bck

DUMP: Volume 1 completed at: Thu Dec 12 02:10:17 2013

DUMP: Volume 1 took 0:00:02

DUMP: Volume 1 transfer rate: 927 kB/s

DUMP: Volume 1 23560kB uncompressed, 1855kB compressed, 12.701:1

DUMP: 23560 blocks (23.01MB) on 1 volume(s)

DUMP: finished in 2 seconds, throughput 11780 kBytes/sec

DUMP: Date of this level 0 dump: Thu Dec 12 02:10:15 2013

DUMP: Date this dump completed: Thu Dec 12 02:10:17 2013

DUMP: Average transfer rate: 927 kB/s

DUMP: Wrote 23560kB uncompressed, 1855kB compressed, 12.701:1

DUMP: DUMP IS DONE

[root@localhost restores]#

Shembulli me lart kryen nje dump te nevelit zero.

Dump i nivelit 0 ben nje backup te plote te te dhenave.

Ndersa dump i nivelit 1,2,3,4,5,6,7,8 funksionojne ne baze te backup te ekziston ne nivelin paraparshes.

  • Fillimisht behet nje backup(dump) i nivelit 0 i cili ben nje kopje fillestare te te gjitha te dhenave.

  • ne skedarin /etc/dumpdates shtohet nje rresht me informacionin mbi kete dumo ( niveli i dump , dhe koha kur eshte bere ky dump)

  • Kur behet nje backup ( dump) i nje niveli me te larte per shembull 1 ( nje) behen backup vetem ndryshimet qe ka pesuar volumi perkates ( drive ..) qe nga backup i nivelit te meparshem ( niveli 0)

  • ne skedarin /etc/dumpdates shtohet nje rresht me informacionin mbi kete dumo ( niveli i dump , dhe koha kur eshte bere ky dump)

  • Kur behet nje backup ( dump) i nje niveli me te larte per shembull 2 ( dy ) behen backup vetem ndryshimet qe ka pesuar volumi perkates ( drive ..) qe nga backup i nivelit te meparshem ( niveli 1)

Ky mekanizem mundeson nje kursim te hapesires per te ruajtur backup si edhe nje shkurtim te kohes qe duhet per te kryer backup-in.

Perdorimi i dump per te bere backup nje pjese te pemes se direktorive

Komanda dump mund te perdoret per te bere backup edhe nje peme te direktorive. Por ne kete rast eshte e mundur qe te kryehen vetem backup te nivelit 0.

Nuk eshte e mundur qe te ruhen ne skedarin etc/dumpdates historiku i dump te nje peme direktorish, kjo gje e shte e mundur vetem per volumet (drive)

Ne skedarin /etc/fstab ruhet nje information mbi ngarkimet e volumeve ne direktorite perkatese:

[root@localhost restores]# cat /etc/fstab

#

UUID=b70528f3-176c-4b8e-aa9a-8bcebbc46437 / ext4 defaults 1 1

UUID=63bb571f-3b05-45bb-b477-7a66e88c4d43 /boot ext4 defaults 1 2

UUID=d2976a68-56aa-4714-922c-5377cf69b5f9 /home ext4 defaults 1 2

UUID=23f3518d-e0ca-4c65-8a60-1374fbadc30e swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

[root@localhost restores]#

Sic duke /home eshte nje particion me vete.

Nese tentojme te bejme nje dump te niveli 0 me opsionin -u ( update /etc/dumpdates) per nje nendirektori te dosjes /home, per shembull /home/student do te merrnim nje mesazh gabimi i cili na njofton qe nuk mund te perdorim kete opsion ne nje nendirektori:

[root@localhost restores]# dump -0 -u -z -L studentbackup -f /root/backups/home.bck /home/student/

DUMP: You can't update the dumpdates file when dumping a subdirectory

DUMP: The ENTIRE dump is aborted.

[root@localhost restores]#

E njejta komande shkon me sukses per dosjen /home pasi ajo eshte ngarkuar ne nje partition me vehte:

[root@localhost restores]# dump -0 -u -z -L studentbackup -f /root/backups/home.bck /home/

DUMP: Date of this level 0 dump: Thu Dec 12 02:51:42 2013

DUMP: Dumping /dev/sda5 (/home) to /root/backups/home.bck

DUMP: Label: studentbackup

DUMP: Writing 10 Kilobyte records

DUMP: Compressing output at compression level 2 (zlib)

DUMP: mapping (Pass I) [regular files]

DUMP: mapping (Pass II) [directories]

DUMP: estimated 23245 blocks.

DUMP: Volume 1 started with block 1 at: Thu Dec 12 02:51:42 2013

DUMP: dumping (Pass III) [directories]

DUMP: dumping (Pass IV) [regular files]

DUMP: Closing /root/backups/home.bck

DUMP: Volume 1 completed at: Thu Dec 12 02:51:43 2013

DUMP: Volume 1 took 0:00:01

DUMP: Volume 1 transfer rate: 1856 kB/s

DUMP: Volume 1 23560kB uncompressed, 1856kB compressed, 12.694:1

DUMP: 23560 blocks (23.01MB) on 1 volume(s)

DUMP: finished in 1 seconds, throughput 23560 kBytes/sec

DUMP: Date of this level 0 dump: Thu Dec 12 02:51:42 2013

DUMP: Date this dump completed: Thu Dec 12 02:51:43 2013

DUMP: Average transfer rate: 1856 kB/s

DUMP: Wrote 23560kB uncompressed, 1856kB compressed, 12.694:1

DUMP: DUMP IS DONE

[root@localhost restores]#

Nese komanda dumo me nivel 0 per dosjen /home/student/ do te ekzekutohet pa opsioni -u (update /etc/dumpdates) atehere backup do te shkonte me sukses:

[root@localhost restores]# dump -0 -z -L studentbackup -f /root/backups/home.bck /home/student/

DUMP: Date of this level 0 dump: Thu Dec 12 02:53:44 2013

DUMP: Dumping /dev/sda5 (/home (dir /student)) to /root/backups/home.bck

DUMP: Label: studentbackup

DUMP: Writing 10 Kilobyte records

DUMP: Compressing output at compression level 2 (zlib)

DUMP: mapping (Pass I) [regular files]

DUMP: mapping (Pass II) [directories]

DUMP: estimated 21718 blocks.

DUMP: Volume 1 started with block 1 at: Thu Dec 12 02:53:44 2013

DUMP: dumping (Pass III) [directories]

DUMP: dumping (Pass IV) [regular files]

DUMP: Closing /root/backups/home.bck

DUMP: Volume 1 completed at: Thu Dec 12 02:53:44 2013

DUMP: 22030 blocks (21.51MB) on 1 volume(s)

DUMP: finished in less than a second

DUMP: Date of this level 0 dump: Thu Dec 12 02:53:44 2013

DUMP: Date this dump completed: Thu Dec 12 02:53:44 2013

DUMP: Average transfer rate: 0 kB/s

DUMP: Wrote 22030kB uncompressed, 1566kB compressed, 14.068:1

DUMP: DUMP IS DONE

[root@localhost restores]#

Nese do te tentojme pas kesaj te bejme nje backup te nje niveli me te madh se niveli zero ( incremental backup) do te merrnim nje meszh gabimi qe na informon qe backup inkrementale nuk jane te mundur per nendirektorite.

[root@localhost restores]# dump -1 -z -L studentbackup -f /root/backups/home.bck /home/student/

DUMP: Only level 0 dumps are allowed on a subdirectory

DUMP: The ENTIRE dump is aborted.

[root@localhost restores]#

Rikthimi i te dhenave nepermjet komandes restore

Komanda restore mundeson rikthimin e te dhenave nga skedari i backupit.

Komanda restore i rikthen te dhenat ne dosjen baze ku ndodhet ( dosja ku ndodhej perdoruesi qe therriti komanden restore)

Komanda restore ka disa opsione, nder te cilet:

-i , percakton qe restore do te kryehet ne menyre interaktive

-r percakton qe restore do te kryhet ne menyre rekursive, duke rikhtyer te gjithe strukturen e direktorive dhe skedaret qe ndodhen ne skedarin e backupt

-f percakton emrin e skedarit te backup.

Rikthimi i te gjithe te dhenave nepermjet komandes restore

Komanda me poshte rikthen ne dosjen /root/restores te gjithe strukturen e direktorive dhe skedaret qe ndodhen ne skedarin e backup-it.

Shembull:

[root@localhost restores]# ls

lost+found restoresymtable student student.gz student.tar

[root@localhost restores]# rm -r -f *

[root@localhost restores]# ls

[root@localhost restores]#

Dosja /root/restores eshte bosh

[root@localhost restores]# restore -r -f /root/backups/home.bck

Dump tape is compressed.

[root@localhost restores]# ls

lost+found restoresymtable student student.gz student.tar

[root@localhost restores]#

Pas restore eshte ngarkuar ne /root/restores permbajtja e skedarit te backupit.

Rikthimi i te dhenave ne menyre interaktive nepermjet komandes restore

Komanda restore i mundeson perdoruesit qe te komumikoje me te nepermjet komandave.

Komanda restore njeh disa komanda nga te cilat:

pwd, ls, cd, add dhe extract.

Nepermjet komandes add zgjidhen skedaret te cilet duhen ekstraktuar nga skedari i backupit dhe me pas komanda extract i ekstrakton keto skedare ne dosjen korrente:

Shembulli me poshte ekstrakton nga backup i /home/ vetem skedarin file3 nga dosja /home/student/docs

Skedaret e ekstraktuar vendosen ne dosjen korrente nga ku therritet komanda restore, qe ne shembullin tone eshte /root/restores/.

Se pari pozicionohemi ne kete direktori dhe e zbrasim ate:

[root@localhost student]# cd /root/restores/

[root@localhost restores]# rm -r -f *

[root@localhost restores]# ls

[root@localhost restores]#

Tani qe dosja /root/restores eshte bosh do te therrasim utilitetin restore

[root@localhost restores]# restore -i -f /root/backups/home.bck

restore > ls

.:

lost+found/ student/ student.gz student.tar

restore > cd /student/docs/

restore > ls

./student/docs:

file3

restore > add file3

restore > extract

You have not read any volumes yet.

Unless you know which volume your file(s) are on you should start

with the last volume and work towards the first.

Specify next volume # (none if no more volumes): 1

set owner/mode for '.'? [yn] y

restore > quit

[root@localhost restores]# ls

student

[root@localhost restores]# ls student/docs/

file3

[root@localhost restores]#

Atributi -i ( interactive) ben qe komanda restore te hapet ne menyren interaktive.

Nepermjet komandes add percaktojme cilet skedare duam te ekstraktojme dhe me pas me komanden extract per te ekstraktuar skedaret.

Vini re qe ekstrakti behet se bashku me pemen e direktotive ku ndodhet skedari file3.