crontab rsync Linux Command with key-gen

Easy way to setting crontab, rsync on linux steps and  commands with ssh-keygen backup purpose. 

What is Cron ? 

Cron is a software utility known as "cron job" it's a time, date based job scheduler in Unix Linux server, client operating systems. Users can set up and maintain software environments with the use of cron to schedule their jobs to run periodically at any fixed times, dates, month, year format.

The crontab is a command that you want to run on a regular schedule, used to manage cron jobs, Crontab stands for "cron table".

What is rsync :- 

Rsync is a powerful synchronization tool, this tool allows you to copy and delete data. 

rsync is also a software utility for efficiently transferring and synchronizing data files between a servers and clients computer and an external hard drive and across networked computers by comparing the modification times and sizes of files. 

It is commonly found on Linux/ Unix operating systems. rsync is written in C programming language as a single threaded application program.

Some of the frequent used command in rsync : 

-a : archive mode, archive mode allows copying files recursively and it also preserves symbolic links, file permissions, user & group ownerships and timestamps

-h : human-readable, output numbers in a human-readable format

-v : verbose

-r : copies data recursively (but don’t preserve timestamps and permission while transferring data

-z : compress file data

#rsync /source path  /destination path

#rsync -v /home/user/test.tex  /home/test/backup

rsync command to copy sync data on remote machine 

#rsync -av /var/www/html/user-data  user2@

this command will ask for your password to perform the task.

We can use this to execute on regular basis to take backup daily using "crontab" 

How to automatically run script using "crontab" 

Just go ahead and save this above command in a script file and make it executable. 

To add a crontab job, type the following command at a UNIX/Linux shell prompt:

# crontab -e

#Add the following line:

#1(min) 2(hours) 3(day) 4(month) 5(Day of the week



1: Minutes (0-59)

2: Hours (0-23)

3: Days (1-31)

4: Month (1-12)

5: Day of the week(1-7)

/script/file/path - on your shell script

for example suppose if you wish to run your backup script at 11:50PM IST.

# crontab -e

#Add this following line:

50 23 * * * /root/

Here the first entry indicates for minute and second for hour and next all * indicates for daily between (1-31 days), (1-12 Month), (1-7 Day of the week). 

In this case we also have to make sure that between source to destination machine the communication must be password less, to make it password less click here this link. 

Previous Post
Next Post
Related Posts