how to copy folders from one server to another in ubuntu using regular intervals automatically
To copy folders from one server to another in Ubuntu using regular intervals automatically, you can use a combination of the rsync
command and a cron job. Here's how you can do it:
Open a terminal on the source server.
Install
rsync
if it's not already installed by running the following command:sudo apt-get install rsync
Use the
rsync
command to copy the folder from the source server to the destination server. The basic syntax is as follows:rsync -avz /path/to/source/folder user@destination:/path/to/destination/folder
Replace/path/to/source/folder
with the actual path of the folder you want to copy,user
with the username of the destination server, and/path/to/destination/folder
with the actual path of the destination folder.Test the
rsync
command to ensure that it works as expected.Once you are satisfied with the
rsync
command, you can automate the process by creating a cron job. Open the crontab file by running the following command:crontab -e
Add a new line to the crontab file with the following format:
/interval * rsync -avz /path/to/source/folder user@destination:/path/to/destination/folder
Replaceinterval
with the desired time interval in minutes. For example, if you want to run the command every 30 minutes, use*/30
.Save the crontab file and exit the text editor.
Now, the specified folder will be automatically copied from the source server to the destination server at the specified time intervals.
Please note that you may need to set up SSH key-based authentication between the servers to avoid entering the password every time the rsync
command is executed.