WIP: onie-tools: add a tool for configuration backup#315
WIP: onie-tools: add a tool for configuration backup#315KanjiMonster wants to merge 9 commits intomainfrom
Conversation
In order to keep stdout clean, move all instanced of DEBUG output to stderr. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
The two paths for enabled and disabled services have nothing in common, so let's split these to two functions to avoid one level of indentation. No functional changes. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
Move apply fixups to the backup of files, since they belong together. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
Only create .SERVICES_{DIS,EN}ABLED when not empty on backup, else the
check for if we even backed up anything would always trigger since we
would always have these files.
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
f8c3954 to
2b31b74
Compare
Instead of directly copying files while parsing backup configuration, just create a list of files to copy, then copy everthing in one step. As a side effect this allows using "-/" to prevent backup of any files (it won't prevent backing up system service states though). Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
To be able to tell users what will be backed up, make the backup function only output what will be backed up if the enviornment variable DRYRUN is set. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
In order to have the backup library available in BISDN Linux, move it into the onie-tools package and pull it from there during image generation. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
Enable the comm applet as it's needed for our configuration backup scripts. Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
Add a simple configuration backup and restore tool. It has three modes: - backup: create a backup as a gzipped tar - restore: restore a previous backup - list: list everything that would be backed up Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
2b31b74 to
dd2fcc9
Compare
|
I welcome the possibility to dry-run and test the backup process without going through a reinstallation of the OS. |
Thanks! And what do you think of the (example) output? Do you think it is understandable that way? |
| if [ -d "$oldpath" ]; then | ||
| for path in $oldpath/*; do | ||
| [ -e "$path" ] || break | ||
| add_to_backup "/${path#${2%/}/}" $2 $3 |
There was a problem hiding this comment.
A comment explaining this line might be helpful.
| *.service) | ||
| service_file=$(readlink $1/etc/systemd/system/multi-user.target.wants/$service) | ||
| base=$(basename $service_file) | ||
| preset=$(grep "$base" $1/lib/systemd/system-preset/*.preset | cut -d ':' -f 2 | cut -d ' ' -f 1) |
There was a problem hiding this comment.
A comment explaining the format we are processing here maybe?
| for file in $1/var/lib/opkg/info/*.conffiles; do | ||
| [ -f "$file" ] || break | ||
| parse_file $file "+" $1 $2 | ||
| add_files="$(echo -e "$add_files\n$(parse_file $file "+" $1 $2)")" |
There was a problem hiding this comment.
An explanation might be useful here, too.
| Example usage: | ||
| $(basename "$0") -b bisdn-linux-backup.tgz | ||
|
|
||
| For additional information, see the man page for onie-bisdn-backup(1). |
There was a problem hiding this comment.
Make sure the man page is actually there.
There was a problem hiding this comment.
This is why the PR is still a draft, I didn't want to bother writing a man page just to have to rewrite it because the output should look totally different.
| -h show this message | ||
| -l list backup contents (show only what would be backed up) | ||
| -b <FILENAME> create a tar.gz configuration backup as <FILENAME> | ||
| -r <FILENAME> restore a tar.gz configuraton backup from <FILENAME> |
There was a problem hiding this comment.
| -r <FILENAME> restore a tar.gz configuraton backup from <FILENAME> | |
| -r <FILENAME> restore a tar.gz configuration backup from <FILENAME> |
|
|
||
| BACKUP_FILE= | ||
| MODE= | ||
|
|
There was a problem hiding this comment.
Not passing any arguments should give the same result as -h (instead of "Please run this program as root" or some such).
| disabled_services=$(collect_disabled_services $1) | ||
|
|
||
| if [ -n "$DRYRUN" ]; then | ||
| echo "Services to enable:" |
There was a problem hiding this comment.
As a user, I would wonder what this actually does (if I create a backup while, where do I find the backup for the service state?). Maybe the usage text or the man page could elaborate (list stored in .SERVICES_ENABLED/.SERVICES_DISABLED, then enabled/disabled via systemctl).
There was a problem hiding this comment.
Definitely rather something for the man page.
In order to make configuration handling on BISDN Linux more transparent and user friendly, let's add a tool for creating and restoring backups.
The tool can be used in three ways:
In order to make it work the same as backing up when upgrading, the code from the installer is reused as a library. To allow this, the file is moved here.