I'm hosting a page and have ssh-access to the webspace.
The site allows modification by it's users. To be able to revert it back to an older state, I thought about rsync to create an incremental backup every 30 minutes using cron to launch the following script.
#!/bin/bash
# Binaries
RSYNC=`which rsync`
LN=`which ln`
MKDIR=`which mkdir`
#TODO: Is this enough to make the script distro independent?
# Other Variables
source="<username>@<provider>:<workspace path>"
target="<local backup path>"
# Date ...
year=$(date +%Y)
month=$(date +%m)
day=$(date +%d)
# ... and time
hour=$(date +%H)
minute=$(date +%M)
# Prepare directories
$MKDIR -p $target/$year/$month/$day/"$hour"_"$minute"/
# TODO: Why is this necessary? The actual backup won't work without this line
# saying "directory does not exist...".
# Actual backup
$RSYNC -av --delete "$source" "$target/$year/$month/$day/"$hour"_"$minute"/" --link-dest="$target/latest/"
$LN -nsf "$target/$year/$month/$day/"$hour"_"$minute"/" "$target/latest"
# End script
exit 0
The script seems to work so far but the target-path bloated to roughly three times the actual size of the source path within in the last three days.
Incremental backuping should only lead to a small increase, right?
What am I doing wrong?
Thanks in advance
Markus
my-backups/2018-04-29
,my-backups/2018-04-30
,my-backups/2018-05-01
etc. When I dodu -hs 2018-04-29
then it returns ±200GB (=full backup), and almost the same fordu -hs 2018-04-30
...du -hs 2018-04-29 2018-04-30
(i.e. both directories in one go), then it returns ±200GB for the first and just ±5GB (=incremental backup) for the second. I think in that casedu
notices that most files in …30 are hardlinked with files in …29 and only counts them once.$target
, on an ext4 filesystem? Else the hardlinks won't work and you won't save any space.