Call it whatever you want, backup, backup, backup, but do it. Backups are vital to avoid data loss and are often forgotten. This costs a lot of trouble and money to many companies, but also to home users who see their documents or work disappear overnight. Either due to a failure in the hard drive, due to a software problem that leaves the data corrupted, due to ransomware, etc. And here you can learn how to do it with rsync.
Remember that to avoid data loss, if you carry a good policy backup you can preserve your data or most of them. Remember to make frequent copies (appropriate to the amount of new data that you generate and the importance of it) and do it on secure media. That is, do not store them on perishable media such as optical discs that can be scratched ...
There are several types of backup, and the one that interests me here is the incremental copy that will be done without installing anything, only with the rsync tool that you will already find in your distro.
Types of backups
If you still don't know what is an incremental backup, and the differences with other types, basically stick with this:
- Logistics: all files that may be in a drive or directory are copied.
- Incremental- Will only copy files that have been modified after a previous full or differential backup. To do this, it compares the modification dates of the source files and those of the previous copy and if there are differences, the software will make the decision to copy only those that have been modified. The good thing about this copy is that it is not as heavy as the full one and allows you to update only what you are interested in.
- Differential: it is something in between full and incremental. That is, it will copy both files that have been created new and those that have been modified.
How to create the copies with rsync
Although the title only mentions the incrementals, I will also include the others, since I do not like any work and it will surely be good for you to remember the commands for that.
- In the full backup:
rsync -avh /ruta/origen /ruta/destino
- In the incremental backup:
rsync -avhb --delete --backup-dir=/ruta/destino/copia_$(date +%d%m%Y%H%M) /ruta/origen/ /ruta/destino/
- For the differential, if you even want to do it from a script to schedule it daily, weekly or monthly, you can use this code:
#!/bin/bash DAY=$(date +%A) if [ -e /ruta/copia/incr/$DAY ] ; then rm -fr /ruta/copia/incr/$DAY fi rsync -a --delete --quiet --inplace --backup --backup-dir=/ruta/copia/incr/$DAY /ruta/origen/ /ruta/destino/