I had some code lying around from another project and I minified it. I use this to automatically do incremental backups of my home assistant folder (or only the config one). I put it with 5 minute delay and run it with cron.
What this does:
- first time, it makes a full copy of your folder in /backups/year_month_day_hour_minute_second
- second time and afterwards, it makes hard links to the previous backup, then copies the changes over
Non-technical: It makes a backup of your files, copying the least amount of data possible. Each backup looks like it has all the files, but it only contains the difference. If you have a 100MB folder, and made 3 backups with 5 MB for each 2 changes, you would need:
- 100 mb for first backup
- ~5MB for second backup
- ~5MB for third backup
github: https://github.com/vladbabii/php_rsync_incremental_backups
original ideal: http://www.mikerubel.org/computers/rsync_snapshots/
How to use:
-
install php-cli
-
copy the .php file somewhere on your server
-
edit the first part of the file
$C[‘timezone’ ] = ‘America/New_York’;
$C[‘from’ ] = ‘/path/to/config/files’;
$C[‘to’ ] = ‘/path/to/backups’;
$C[‘keep’ ] = 1000;
$C[‘rounding’ ] = 605;
$C[‘rsync’ ] = ‘rsync’;
$C[‘behind’ ] = 201604; -
set it up with cron every X minutes
Values:
- to / from
- timezone: see http://php.net/manual/en/timezones.php
- keep - how many backups to keep
- rounding - make a backup at most X seconds (in the above example: 5 minutes)
- rsync executable path
- behind - how many backups to look back for a good one for the diff