Most of us must have experienced the loss of valuable files and data at some point in our lives. We know the importance of backing up our files and data, but few have implemented a proper backup solution.
One of the main reasons is when a local storage system fails. Good backup strategies include creating a consistent and automatic backup and storing one of the backups in a remote location.
A common method to backup a Linux server or desktop is using rsync to transfer files to a remote SSH server. cron is then used to automate the backup process.
Related: How to SSH without password
remoteuser@remoteserver:$ mkdir -p ~/backup_folder/folder_01
remoteuser@remoteserver:$ chmod -R 777 ~/backup_folder/folder_01
localuser@localhost:$ rsync -av --delete /path/to/folder_01/ remoteuser@remoteserver:backup_folder/folder_01
Sample of a more complete script for automated backup.
#!/bin/bash TARGET="remoteuser@remoteserver:~/backup_folder" for i in folder_01 folder_02 folder_03; do rsync -av --delete $i/ $TARGET/$i; done
remoteuser@remoteserver:$ ls -l ~/backup_folder/folder_01
localuser@localhost:$ crontab -e
# 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
Comment anonymously. Login not required.