Ubuntu Server Guide
Download 1.23 Mb. Pdf ko'rish
|
ubuntu-server-guide (1)
- Bu sahifa navigatsiya:
- Simple Shell Script
Resources
• For more Bacula configuration options, refer to Bacula’s Documentation. • The Bacula Home Page contains the latest Bacula news and developments. • Also, see the Bacula Ubuntu Wiki page. Shell Scripts One of the simplest ways to backup a system is using a shell script. For example, a script can be used to configure which directories to backup, and pass those directories as arguments to the tar utility, which creates an archive file. The archive file can then be moved or copied to another location. The archive can also be created on a remote file system such as an NFS mount. The tar utility creates one archive file out of many files or directories. tar can also filter the files through compression utilities, thus reducing the size of the archive file. Simple Shell Script The following shell script uses tar to create an archive file on a remotely mounted NFS file system. The archive filename is determined using additional command line utilities. 293 #!/ b i n / bash #################################### # # Backup t o NFS mount s c r i p t . # #################################### # What t o backup . b a c k u p _ f i l e s =”/home / var / s p o o l / m a i l / e t c / r o o t / boot / opt ” # Where t o backup t o . d e s t =”/mnt/ backup ” # C r e a t e a r c h i v e f i l e n a m e . day=$ ( d a t e +%A) hostname=$ ( hostname −s ) a r c h i v e _ f i l e =”$hostname−$day . t g z ” # P r i n t s t a r t s t a t u s message . echo ” Backing up $ b a c k u p _ f i l e s t o $ d e s t / $ a r c h i v e _ f i l e ” d a t e echo # Backup t h e f i l e s u s i n g t a r . t a r c 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 t end s t a t u s message . echo echo ” Backup f i n i s h e d ” d a t e # Long l i s t i n g o f f i l e s i n $ d e s t t o check f i l e s i z e s . l s −l h $ d e s t • $backup_files: a variable listing which directories you would like to backup. The list should be cus- tomized to fit your needs. • $day: a variable holding the day of the week (Monday, Tuesday, Wednesday, etc). This is used to create an archive file for each day of the week, giving a backup history of seven days. There are other ways to accomplish this including using the date utility. • $hostname: variable containing the short hostname of the system. Using the hostname in the archive filename gives you the option of placing daily archive files from multiple systems in the same directory. • $archive_file: the full archive filename. • $dest: destination of the archive file. The directory needs to be created and in this case mounted before executing the backup script. See ??? for details of using NFS. • status messages: optional messages printed to the console using the echo utility. • tar czf 𝑑𝑒𝑠𝑡/archive_file $backup_files: the tar command used to create the archive file. Download 1.23 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling