Rufwoof, gave me the idea of using rsync to create a snapshot of a savefile (see post). The part that interested me was using hardlinks to minimize the size of the save file snapshot.
To 'save changes' you just rm the hardlink copy folder, and recreate a new hardlinks rsync, which being just inodes (not actual data) is incredibly quick. To 'not save' you just rm the main folder, rename the hardlink folder as the main folder and create another hardlink rsync of that. A few seconds either way even for something like a main sfs of 500MB or more.
So for example say, I wanted to create a copy of my savefile called bustersave and save it into a folder called buster_save_hl1
Code: Select all
rsync -rltDv --link-dest=$PWD/bustersave/ $PWD/bustersave/ $PWD/buster_save_hl1/
https://linux.die.net/man/1/rsync
Some notes, here:
1. the trailing forward slashes are necessary;
2. absolute paths are necessary (that is why I'm using the $PWD);
3. if you do steps #1 and #2 correct, not much output is given to show progress (consequently you might want to also add the --stats options to print more progress information);
4. the directory were the hardlinks are located (3rd last argument: --link-dest=$PWD/bustersave/=$PWD/bustersave/) has to be on the same file system as the destination (last argument);
5. we can speed things up by avoiding copying certain directories (e.g. root) which has a lot of stuff we likely don't need (e.g. browser .cache). One way to do this is perhaps to bind the folders we went to a separate directory and then copy this new source directory (2nd last argument).
6. Since hard links are used this isn't an exact copy because if we modify a file, it affects both the original and the snapshot, unless we first break the hardlink (for example by deleting and then copying).
7. We can't use the -a option in some cases because this implies the following options "-pgo". See:
https://gist.github.com/certik/3398185
the -a option didn't create hardlinks for me on a usb drive even when done on a linux partition.
8. The -pgo options are for "premissions" "group" "owner" if we are only creating hardlinks we probably don't need these options anyway, since the hard link points to the original file.