Losing valuable files and data is a frustrating experience many of us have faced. While we understand the importance of backing up our files and data, not everyone has implemented an effective backup solution.
A major cause of data loss is the failure of a local storage system. Good backup strategies involve creating regular, automatic backups and storing at least one copy at a remote location.
A popular method to back up a Linux server or desktop is to use rsync for transferring files to a remote SSH server, and cron for automating the backup process.
Steps to set up automatic remote backup with SSH and rsync:
- Set up a passwordless SSH login from your local machine to the remote backup server.
- Create a directory on the remote server to serve as a backup target.
remoteuser@remoteserver:$ mkdir -p ~/backup_folder/folder_01
- Ensure the connecting SSH user has full access to the directory on the remote backup server.
remoteuser@remoteserver:$ chmod -R 777 ~/backup_folder/folder_01
- Run your backup script manually on your local machine to test the success of the backup operation.
localuser@localhost:$ rsync -av --delete /path/to/folder_01/ remoteuser@remoteserver:backup_folder/folder_01
Sample of a more complete script for automated backup.
- backup.sh
#!/bin/bash TARGET="remoteuser@remoteserver:~/backup_folder" for i in folder_01 folder_02 folder_03; do rsync -av --delete $i/ $TARGET/$i; done
- Verify on the remote server that the files have been successfully backed up.
remoteuser@remoteserver:$ ls -l ~/backup_folder/folder_01
- Open the crontab editor on your local machine.
localuser@localhost:$ crontab -e
- Configure cron on your local machine to automatically execute your backup script at a specified.
# Run backup command every day on midnight, sending the logs to a file. 0 0 * * * rsync -av --delete /path/to/folder_01/ remoteuser@remoteserver:backup_folder/folder_01 >>~/.backup.log 2>&1
Related: Crontab Generator
- Save and exit the crontab editor.
![](https://www.simplified.guide/_media/page/author/shakir/mohd-shakir-zakaria.jpg?w=200&tok=d15487)
Author: Mohd
Shakir Zakaria
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
![](data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABOElEQVRIia2VYXHDMAyFPwiBEAiBYAYLg5lBC8EQyqBmsDFoGKQMFgYNg+1H5jtFtmMn6bvzj9jWe7IUSVBGD9yBh1p34KPCPosr8AJ+C+sFXPYQd8BYQazX+G9bJK/xeus1WRFJ7oAGsMAkCCbgKb5ncbcXIm1KQBoasd9kvGoTRDJcK1jWT+1THhTQKg4rD+c3CUien3BgFPlwgDzAKS4DcGPjaTvRKa4bLB5HqicQReOdAk2NwPWEgKkReJwQ0PkcALzaPBqmhrjNeIiLLJT7HpFcg7RBWcbfsQ7XhXyr+GSZC7nm14TLXnjeERdMKvH6n9fLa29CmYckO5YkfUtPFKYM+Uyio1pxoXZCDRkBmzPw4tIIfLH926YEfMkrlzCqFaguUsN6AJUEnhxsMT1LknNwFGbHH5UF4DVNwliLAAAAAElFTkSuQmCC)
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.