1 . create a shell file and store it wherever you want (it’s recommended to store it on /home/<user>)


# Set variables
DATE=$(date +"%Y-%m-%d")

# Create backup file
tar -czvf /tmp/backup-$DATE.tar.gz $SRC_DIR

# Copy backup file to remote server
rsync -avz -e ssh /tmp/backup-$DATE.tar.gz $DEST_USER@$DEST_HOST:$DEST_DIR

# Remove temporary backup file
rm /tmp/backup-$DATE.tar.gz

2. make this file executable :

chmod +x /home/user/backup.sh

3. open crontab by :

crontab -e

4. add a record , for example I force to run this shell script every day :

0 0 * * * /home/user/backup.sh

  1. Save and exit the crontab file.

This script will create a compressed tar file of the entire root directory (/) and store it in the /tmp directory with a filename that includes the current date. It will then use the rsync command to copy the backup file to the remote server specified by DEST_HOST, DEST_USER, and DEST_DIR. Finally, it will remove the temporary backup file.

Note that you may need to modify the script to exclude certain directories or files from the backup, or to use a different backup method depending on your specific requirements.

6. create a ssh key on source server :


7. add public key to destination server :
open destination server and copy pub key from source server and add it at the end of file “~/.ssh/authorized_keys” to destination server and save and close .

Leave a Reply

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