Crontab Function

How t install and configure backup in crontab

Daily/Weekly/monthly Schedule Backup Linux

* * * * * minute (0-59) ( have to use 5 digits * star or time selection)

* * * * HOUR(0-23)

* * *  DAY OF MONTH (1-31)

* * MONTH (1-12)

* WEEK (0-6)

(

Run a cron job every minute

 * * * * * /path/to/script.sh        

Run a cron job after every 10 minutes

 

*/10 * * * * /path/to/script.sh

Run a cron job on specific months

To schedule a cron job to execute on specific months e.g. March, august, December, add the cron job in your crontab file

* * * jan,may,aug * /path/to/script.sh

Run a cron job on selected days

If you would like your cron job to be executed on selected days let’s suppose Sunday and Friday at 5 PM

 

0 17 * * sun,fri /path/to/script.sh

 

Run a cron job daily at a specific time

 

0 3 * * * /path/to/script.sh

 

Run a cron job on a specific day

 

0 0 * * SUN /path/to/script.sh

 

 Run multiple tasks in a single cron job

To schedule multiple tasks in a single cron job, add all scripts in your crontab file by separating them with a semicolon

 

* * * * * /path/to/script1.sh; /path/to/script2.sh

 

Run a cron job on every weekday

 

To schedule a cron job to execute on every day of the week that is from Monday to Friday

 

0 0 * * 1-5 /path/to/script.sh

 

Run a cron job twice a day

To schedule a job to run two times a day e.g. at 6 am and 3 pm, you will need to add this line

0 6,15 * * * /path/to/script.sh

Run a cron job every hour

To schedule a cron job to execute every hour at minute 0, you will need to add this line

0 * * * * /path/to/script.sh

Run a cron job after every 3 hrs

0 */3 * * * /path/to/script.sh

Run cron job at 4:00 pm on the first of every month

0 16 1 * * /path/to/script.sh

 

)

Backup Resource (Host)

[root@BKPVOL ~]# yum install rsync -y

[root@rserver8 ~]# rpm -qa | grep rsync

[root@rserver8 ~]# yum install rsync -y

[root@rserver8 ~]# rpm -qi rsync

[root@rserver8]# ssh-keygen

[root@rserver8]# ssh-copy-id -i root@192.168.60.36

[root@BKPVOL ~]# ssh root@192.168.60.40

Backup script

backup.sh is in root directory

[root@rserver8]# vi /root/backup.sh

[root@BKPVOL ~]# vi /root/backup.sh

{

#!/bin/bash

/usr/bin/rsync -av -e ssh /var/www/html* root@192.168.60.40:/etc/appvolbkp/

/usr/bin/rsync -av -e ssh /var/lib/mysql* root@192.168.60.40:/etc/appvolbkp/Database

}

/usr/bin/rsync -av -e ssh /var/www/html* root@192.168.60.40:/10bkp/

Edit crontab

Run a cron job on a specific day

0 0 * * SUN /bin/bash /root/backup.sh

Run a cron job on selected days

0 17 * * sun,fri /bin/bash /root/backup.sh

Run a cron job on specific months

* * * jan,may,aug * /bin/bash /root/backup.sh

Run a cron job every minute

* * * * * bin/bash /root/backup.sh

Run a cron job daily at a specific time

0 3 * * * bin/bash /root/backup.sh

 

To edit the crontab file

crontab –e

[root@rserver8 backup]# crontab -e

View crontab

view crontab file

crontab -l

[root@BKPVOL ~]# tail -f /var/log/cron

Backup destination Server –

[root@volbackup]# rpm -qa | grep rsync

[root@volbackup]# yum install rsync -y

[root@rserver8 etc]# mkdir -p appvolbkp

[root@rserver8 ~]# cd /etc/appvolbkp/

Leave a Reply

Your email address will not be published. Required fields are marked *