You are on page 1of 3

2/28/2014

Archive Rotation

Archive Rotation
The shell script in Shell Scripts only allows for seven different archives. For a server whose data doesn't change often, this may be enough. If the server has a large amount of data, a more complex rotation scheme should be used. Rotating NFS Archives Tape Drives

Rotating NFS Archives


In this section, the shell script will be slightly modified to implement a grandfather-father-son rotation scheme (monthly-weekly-daily): 1. The rotation will do a daily backup Sunday through Friday. 2. On Saturday a weekly backup is done giving you four weekly backups a month. 3. The monthly backup is done on the first of the month rotating two monthly backups based on if the month is odd or even. Here is the new script: # ! / b i n / b a s h # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #B a c k u pt oN F Sm o u n ts c r i p tw i t h #g r a n d f a t h e r f a t h e r s o nr o t a t i o n . # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #W h a tt ob a c k u p . b a c k u p _ f i l e s = " / h o m e/ v a r / s p o o l / m a i l/ e t c/ r o o t/ b o o t/ o p t " #W h e r et ob a c k u pt o . d e s t = " / m n t / b a c k u p " #S e t u pv a r i a b l e sf o rt h ea r c h i v ef i l e n a m e . d a y = $ ( d a t e+ % A ) h o s t n a m e = $ ( h o s t n a m es ) #F i n dw h i c hw e e ko ft h em o n t h1 4i ti s . d a y _ n u m = $ ( d a t e+ % d ) i f( ($ d a y _ n u m< =7) ) ;t h e n w e e k _ f i l e = " $ h o s t n a m e w e e k 1 . t g z " e l i f( ($ d a y _ n u m>7& &$ d a y _ n u m< =1 4) ) ;t h e n w e e k _ f i l e = " $ h o s t n a m e w e e k 2 . t g z " e l i f( ($ d a y _ n u m>1 4& &$ d a y _ n u m< =2 1) ) ;t h e n w e e k _ f i l e = " $ h o s t n a m e w e e k 3 . t g z " e l i f( ($ d a y _ n u m>2 1& &$ d a y _ n u m<3 2) ) ;t h e n w e e k _ f i l e = " $ h o s t n a m e w e e k 4 . t g z " f i #F i n di ft h eM o n t hi so d do re v e n .
https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html 1/3

2/28/2014

Archive Rotation

m o n t h _ n u m = $ ( d a t e+ % m ) m o n t h = $ ( e x p r$ m o n t h _ n u m%2 ) i f[$ m o n t he q0] ;t h e n m o n t h _ f i l e = " $ h o s t n a m e m o n t h 2 . t g z " e l s e m o n t h _ f i l e = " $ h o s t n a m e m o n t h 1 . t g z " f i #C r e a t ea r c h i v ef i l e n a m e . i f[$ d a y _ n u m= =1] ;t h e n a r c h i v e _ f i l e = $ m o n t h _ f i l e e l i f[$ d a y! =" S a t u r d a y "] ;t h e n a r c h i v e _ f i l e = " $ h o s t n a m e $ d a y . t g z " e l s e a r c h i v e _ f i l e = $ w e e k _ f i l e f i #P r i n ts t a r ts t a t u sm e s s a g e . e c h o" B a c k i n gu p$ b a c k u p _ f i l e st o$ d e s t / $ a r c h i v e _ f i l e " d a t e e c h o #B a c k u pt h ef i l e su s i n gt a r . t a rc z f$ d e s t / $ a r c h i v e _ f i l e$ b a c k u p _ f i l e s #P r i n te n ds t a t u sm e s s a g e . e c h o e c h o" B a c k u pf i n i s h e d " d a t e #L o n gl i s t i n go ff i l e si n$ d e s tt oc h e c kf i l es i z e s . l sl h$ d e s t / The script can be executed using the same methods as in Executing the Script. It is good practice to take backup media off-site in case of a disaster. In the shell script example the backup media is another server providing an NFS share. In all likelihood taking the NFS server to another location would not be practical. Depending upon connection speeds it may be an option to copy the archive file over a WAN link to a server in another location. Another option is to copy the archive file to an external hard drive which can then be taken off-site. Since the price of external hard drives continue to decrease, it may be cost-effective to use two drives for each archive level. This would allow you to have one external drive attached to the backup server and one in another location.

Tape Drives
A tape drive attached to the server can be used instead of an NFS share. Using a tape drive simplifies archive rotation, and makes taking the media off-site easier as well. When using a tape drive, the filename portions of the script aren't needed because the data is sent directly to the tape device. Some commands to manipulate the tape are needed. This is accomplished using mt, a magnetic tape control utility part of the cpio package. Here is the shell script modified to use a tape drive:
https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html 2/3

2/28/2014

Archive Rotation

# ! / b i n / b a s h # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #B a c k u pt ot a p ed r i v es c r i p t . # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #W h a tt ob a c k u p . b a c k u p _ f i l e s = " / h o m e/ v a r / s p o o l / m a i l/ e t c/ r o o t/ b o o t/ o p t " #W h e r et ob a c k u pt o . d e s t = " / d e v / s t 0 " #P r i n ts t a r ts t a t u sm e s s a g e . e c h o" B a c k i n gu p$ b a c k u p _ f i l e st o$ d e s t " d a t e e c h o #M a k es u r et h et a p ei sr e w o u n d . m tf$ d e s tr e w i n d #B a c k u pt h ef i l e su s i n gt a r . t a rc z f$ d e s t$ b a c k u p _ f i l e s #R e w i n da n de j e c tt h et a p e . m tf$ d e s tr e w o f f l #P r i n te n ds t a t u sm e s s a g e . e c h o e c h o" B a c k u pf i n i s h e d " d a t e The default device name for a SCSI tape drive is / d e v / s t 0 . Use the appropriate device path for your system. Restoring from a tape drive is basically the same as restoring from a file. Simply rewind the tape and use the device path instead of a file path. For example to restore the / e t c / h o s t sfile to / t m p / e t c / h o s t s : m tf/ d e v / s t 0r e w i n d t a rx z f/ d e v / s t 0C/ t m pe t c / h o s t s

https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html

3/3

You might also like