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.
rsyncif it's not already installed by running the following command:
sudo apt-get install rsync
rsynccommand 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/folderReplace
/path/to/source/folderwith the actual path of the folder you want to copy,
userwith the username of the destination server, and
/path/to/destination/folderwith the actual path of the destination folder.
rsynccommand to ensure that it works as expected.
Once you are satisfied with the
rsynccommand, you can automate the process by creating a cron job. Open the crontab file by running the following command:
Add a new line to the crontab file with the following format:
/interval * rsync -avz /path/to/source/folder user@destination:/path/to/destination/folderReplace
intervalwith the desired time interval in minutes. For example, if you want to run the command every 30 minutes, use
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.