In the Ubuntu environment, You will create two separate BASH scripts that will p
ID: 3596584 • Letter: I
Question
In the Ubuntu environment, You will create two separate BASH scripts that will perform two types of backups of a given source directory and store the backed up files in a given target directory (preferably on a separate drive). The first script will perform a full backup and the second script will perform an incremental backup on the remaining days of the week. For assistance with this, Google “incremental backup script in bash” for starters. Once you have these scripts working, use the cron command to schedule the scripts. As the previous steps dictate, you will set up a schedule for the first script (the full backup script) to run on Sundays and Wednesdays and a schedule for the second script (the incremental backup script) to run on the remaining days of the week. Does anyone know how to do this?
Explanation / Answer
Create file using vi editor and paste below script.
$ vi /backup.sh
#!/bin/bash
#Purpose = Backup of Important Data
#Author = Sitaram Chhimpa
#Version 1.0
#START
TIME='date +%b-%d-%y' # This Command will add date in Backup File Name.
FILENAME=backup-$TIME.tar.gz # Here i define Backup file name format.
SRCDIR=/imp-data # Location of Important Data Directory (Source of backup).
DESDIR=/mybackupfolder # Destination of backup file.
tar -cpzf $DESDIR/$FILENAME $SRCDIR
#END
Source directory:
$ mkdir /imp-data
Destination directory:
$ mkdir /mybackupfolder
For setting up cron jobs we use crontab -e command in shell, this command basically says we are going to edit our cron jobs file. If you run first time crontab -e command then it will ask you to default text editor, you just select your favorite editor after that it will never ask you again.
Open cronab editor utility:
$ crontab -e
It has 6 parts see below explanation:
Minutes Hours Day of Month Month Day of Week Command
0 to 59 0 to 23 1 to 31 1 to 12 0 to 6 Shell Command
Keeping above examples in mind now let’s suppose i want to run this backup process on every Sundays and Wednesdays at 1:pm.
in above condition my crontab file should be like this.
#M H DOM M DOW CMND
* * * * 0,3 /bin/bash /backup.sh
That’s All…
This Script will run at Sundays and Wednesdays.
for second scrip we can use
#M H DOM M DOW CMND
* * * * 1,2,4,5,6 /bin/bash /backup2.sh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.