Ubuntu Server Guide Changes, errors and bugs
– c: creates an archive. –
Download 1.27 Mb. Pdf ko'rish
|
ubuntu-server-guide
- Bu sahifa navigatsiya:
- Executing the Script Executing from a Terminal
- Executing with cron
– c: creates an archive.
– z: filter the archive through the gzip utility compressing the archive. – f: output to an archive file. Otherwise the tar output will be sent to STDOUT. • ls -lh $dest: optional statement prints a -l long listing in -h human readable format of the destination directory. This is useful for a quick file size check of the archive file. This check should not replace testing the archive file. This is a simple example of a backup shell script; however there are many options that can be included in such a script. See References for links to resources providing more in-depth shell scripting information. Executing the Script Executing from a Terminal The simplest way of executing the above backup script is to copy and paste the contents into a file. backup.sh for example. The file must be made executable: chmod u+x backup . sh Then from a terminal prompt: sudo . / backup . sh This is a great way to test the script to make sure everything works as expected. Executing with cron The cron utility can be used to automate the script execution. The cron daemon allows the execution of scripts, or commands, at a specified time and date. cron is configured through entries in a crontab file. crontab files are separated into fields: # m h dom mon dow command • m: minute the command executes on, between 0 and 59. • h: hour the command executes on, between 0 and 23. • dom: day of month the command executes on. • mon: the month the command executes on, between 1 and 12. • dow: the day of the week the command executes on, between 0 and 7. Sunday may be specified by using 0 or 7, both values are valid. • command: the command to execute. To add or change entries in a crontab file the crontab -e command should be used. Also, the contents of a crontab file can be viewed using the crontab -l command. To execute the backup.sh script listed above using cron. Enter the following from a terminal prompt: sudo c r o n t a b −e Note Using sudo with the crontab -e command edits the root user’s crontab. This is necessary if you are backing up directories only the root user has access to. 311 Add the following entry to the crontab file: # m h dom mon dow command 0 0 * * * bash / u s r / l o c a l / b i n / backup . sh The backup.sh script will now be executed every day at 12:00 pm. Note The backup.sh script will need to be copied to the /usr/local/bin/ directory in order for this entry to execute properly. The script can reside anywhere on the file system, simply change the script path appropriately. For more in-depth crontab options see References. Download 1.27 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling