Advantages of backups with rotation.
Performing backup rotation using a script has several advantages:
1. Saving storage space: Rotating backups allows you to optimize the use of disk space. Instead of creating a new full copy each time a backup is performed, the script can only save the changes that have occurred since the last backup. Thus, you can significantly save disk space.
2. Simplify management and recovery: Backup rotation makes it easy to manage and find the right backup version. A strategy for storing multiple generations of backups is usually used, such as daily, weekly, or monthly. This simplifies the data recovery process, as you can choose a specific point in time for recovery that meets your requirements.
3. Data corruption protection: Backup rotation minimizes the risk of data corruption or loss. If one of the backups becomes unusable or corrupted, there is always access to previous versions, which provides an additional layer of protection.
4. Regular backups: Using a rotation script usually means automating the process of creating backups. You can set up the script to run regularly on a schedule to keep your data protected at all times. This eliminates the need for manual backups and reduces the chances of skipping this critical step.
5. Flexibility and customization: Backup rotation scripts usually allow you to customize the storage and rotation settings according to your requirements. You can define how many generations of backups to keep, what types of backups to create (full, incremental or differential) and how often to rotate. This allows you to tailor the backup process to your unique needs and system constraints.
In general, the use of scripts with backup rotation provides an efficient and flexible approach to ensuring the security and safety of data, making it easier to manage backups and restore information if necessary.
For the basis, you can take the script described earlier, and change it. This script is an example of a rotation backup script for a website without a server control panel located at /var/www . An example of a backup script with a rotation of 7 days. The script can be downloaded from GitHub.
mv www-dump-6.tar.gz www-dump-7.tar.gz
mv www-dump-5.tar.gz www-dump-6.tar.gz
mv www-dump-4.tar.gz www-dump-5.tar.gz
mv www-dump-3.tar.gz www-dump-4.tar.gz
mv www-dump-2.tar.gz www-dump-3.tar.gz
mv www-dump-1.tar.gz www-dump-2.tar.gz
mv www-dump-0.tar.gz www-dump-1.tar.gz
tar -czf www-dump-0.tar.gz /var/www
It does the following:
Changes to the /backup/www directory, where website backup files are stored.
Deletes the oldest www-dump-7.tar.gz backup to make room for a new copy.
It then performs sequential renaming of the backed up website files. Each copy is renamed to include a higher numbered suffix, for example www-dump-6.tar.gz becomes www-dump-7.tar.gz. This allows you to move all copies up one position, making room for a new copy.
Finally, it creates a new backup of www-dump-0.tar.gz by zipping the /var/www website files using the tar command and the czf flag. The copy created is assigned the lowest number 0, indicating the most recent version.
Thus, the script rotates the backup copies of the website files within 7 days, deleting the oldest copy and shifting all the others. A new copy is created every time the script is run, updating the older version. This allows you to keep the last 7 days of backups and gives you the flexibility to restore a website to a point in time.