-
-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
auto backup #1077
auto backup #1077
Conversation
@mstormi I am in doubt that copying a mounted (writable) partition of a running system on block basis (dd) could work. You will not get a snapshot, but likely in inconsistent state of the filesystem (it might still look ok and by mountable, but the content of the files might point to something completely different due to modifications of the fs during copy). My recommendation would be to try an rsync (file basis) with some special handling of system directories plus some extra efforts to get it bootable etc. |
Thanks for the warning. Yes I know all those horror stories as I've been doing backups for >20 years in different organizations. Also, if you look at the code (beware, that's rapidly prototyped only so not ready yet), you'll see that I prepared for a combination of dd and rsync. My idea is to do raw dumps just once a month and rsync just the diffs all the other days so even if there was a problem with dd, it should get fixed on a subsequent rsync run. |
BTW, supposed to handle #1044 |
We should create a size chart for storage space recommendations for the backup device. with descriptions of how much space will be used for each piece of the backup solution. |
Also, why not use Amanda to create the RAW disk backups? |
Don't think so. Required storage amount is unknown as it depends on compression, runtime config and more.
Thought about that but that would require additional storage space on the order of (at least) the internal SD thus raise HW requirements |
c6aa864
to
6554956
Compare
* implement ext card reader selection based on lsblk Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mirrordrive boot parameter Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mount unit for /backup Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mount unit for /backup Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mirror setup during unattended install Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync.service Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync.service Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * define space for use by Amanda [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * mount and rsync in /usr/local/bin/zramsync Signed-off-by: Markus Storm <markus.storm@gmx.net> * mount and rsync in /usr/local/bin/zramsync [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * fix recursion error in /usr/local/bin/zramsync [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * moved zramsync into zram-config.service as Pre/Post cmds Signed-off-by: Markus Storm <markus.storm@gmx.net> * moved zramsync into zram-config.service as Pre/Post cmds Signed-off-by: Markus Storm <markus.storm@gmx.net> * unattended Amanda install Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * revert oldish changes Signed-off-by: Markus Storm <markus.storm@gmx.net> * use zram-config.service from openhabian-zram repo Signed-off-by: Markus Storm <markus.storm@gmx.net> * use zramsync from openhabian-zram repo Signed-off-by: Markus Storm <markus.storm@gmx.net> * refactored amanda_setup to be able to run unattended Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync install back [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * zram binaries bin -> sbin [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * openhabian.conf.dist [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * force image build Signed-off-by: Markus Storm <markus.storm@gmx.net> * only unattended Amanda install if backupdrive is set in openhabian.conf Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net>
Ok this was quite some twiddling but I think I made it. |
includes/sdrsync.service
Outdated
Type=oneshot | ||
#User=root | ||
#Group=root | ||
ExecStart=source /opt/openhabian/functions/backup.bash; mirror_SD "diff" %DEST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Frankly, I don't know yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it didn't :) but now that I fixed it I think it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, however I do not currently have the ability to test, and would really prefer to have at least a little more testing before merging. @holgerfriedrich any thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functions/backup.bash
Outdated
if [[ -z "$retval" ]]; then return 0; fi | ||
dest="/dev/$retval" | ||
else | ||
dest="${backupdrive:-/dev/sda}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defaulting to /dev/sda could terribly go wrong, just thinking about my local linux box....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you think of adding a few more checks, e.g. src!=dest, dest not mounted (which would also prohibit overwriting your own root partition....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I added a couple of checks and removed the default.
Better?
fi | ||
if [[ "$1" == "raw" ]]; then | ||
echo "Creating a raw partition copy, be prepared this may take long such as 20-30 minutes for a 16 GB SD card" | ||
if ! cond_redirect dd if="${src}" bs=1M of="${dest}"; then echo "FAILED (raw device copy)"; return 1; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markus, as we already discussed, I am concerned about the internal structure of the file system after copy. Inode tables etc of the source file system change during copy and this will always be a high risk to get inconsistent data or a (internally) broken file system.... You may not notice this on a first glance. Can you at least try to safeguard (fschk after copy, rsync again after this)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a fsck.
functions/backup.bash
Outdated
dest="/dev/${retval}" | ||
else | ||
# shellcheck disable=SC2154 | ||
dest="${backupdrive:-/dev/sda}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment below, I think /dev/sda is dangerous default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as below, any thoughts on checking dest before wiping the partion table? (e.g. dest is not the drive your normal installation runs on, dest has no currently mounted partitions, etc... or dest << 128GB (to avoid overwriting normal disks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* implement ext card reader selection based on lsblk Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mirrordrive boot parameter Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mount unit for /backup Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mount unit for /backup Signed-off-by: Markus Storm <markus.storm@gmx.net> * add mirror setup during unattended install Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync.service Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync.service Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * first version mirror_SD [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * define space for use by Amanda [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * mount and rsync in /usr/local/bin/zramsync Signed-off-by: Markus Storm <markus.storm@gmx.net> * mount and rsync in /usr/local/bin/zramsync [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * fix recursion error in /usr/local/bin/zramsync [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * moved zramsync into zram-config.service as Pre/Post cmds Signed-off-by: Markus Storm <markus.storm@gmx.net> * moved zramsync into zram-config.service as Pre/Post cmds Signed-off-by: Markus Storm <markus.storm@gmx.net> * unattended Amanda install Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * revert oldish changes Signed-off-by: Markus Storm <markus.storm@gmx.net> * use zram-config.service from openhabian-zram repo Signed-off-by: Markus Storm <markus.storm@gmx.net> * use zramsync from openhabian-zram repo Signed-off-by: Markus Storm <markus.storm@gmx.net> * refactored amanda_setup to be able to run unattended Signed-off-by: Markus Storm <markus.storm@gmx.net> * add zramsync install back [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * openhabian.conf.dist [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * force image build Signed-off-by: Markus Storm <markus.storm@gmx.net> * only unattended Amanda install if backupdrive is set in openhabian.conf Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * always set initial backup shell+passwd [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * no whitail in non-interactive install Signed-off-by: Markus Storm <markus.storm@gmx.net> * speedup mount units (no separate daemon-reload) Signed-off-by: Markus Storm <markus.storm@gmx.net> * fine select dev/part to mirror Signed-off-by: Markus Storm <markus.storm@gmx.net> * fine select dev/part to mirror Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net> * update NEWS with Auto-backup Signed-off-by: Markus Storm <markus.storm@gmx.net> * minor optimization of constants [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * changes on review Signed-off-by: Markus Storm <markus.storm@gmx.net> * review,shellcheck Signed-off-by: Markus Storm <markus.storm@gmx.net> * do not run Amanda config generation twice Signed-off-by: Markus Storm <markus.storm@gmx.net> * auto backup docs [skip ci] Signed-off-by: Markus Storm <markus.storm@gmx.net> * [skip ci] remove test artifact Signed-off-by: Markus Storm <markus.storm@gmx.net> * add safety checks Signed-off-by: Markus Storm <markus.storm@gmx.net> * shellchecked Signed-off-by: Markus Storm <markus.storm@gmx.net>
Would love you to test this with real HW and get me feedback before we merge. |
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
…ed /storage Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Signed-off-by: Markus Storm <markus.storm@gmx.net>
did anyone test ? |
Closes #1044
Signed-Off-By: Markus Storm markus.storm@gmx.net