Skip to content

Commit 2490a40

Browse files
YeapGuyloomchild
andauthored
Allow backing-up empty volumes (#50)
* Add -a flag to not error on empty volume * Merge -a flag into -f flag * Clean up if condition * Modify readme for new -f behavior * Update README * Update usage --------- Co-authored-by: Jarek Lipski <loomchild@loomchild.net>
1 parent a79bb6f commit 2490a40

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ will clean and restore volume named `some_volume` from `some_archive.tar.bz2` ar
5959
> Don't forget the `-i` switch for interactive operation.
6060
6161
> [!NOTE]
62-
> Restore will fail if the target volume is not empty (use `-f` flag to override).
62+
> Backup will fail if the source volume is empty. Restore will fail if the target volume is not empty. You can use the `-f` flag to override this.
6363
6464
### Restore from a file (deprecated)
6565

volume-backup.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ usage() {
66
>&2 echo "Options:"
77
>&2 echo " -c <algorithm> chooose compression algorithm: bz2 (default), gz, xz, pigz, zstd and 0 (none)"
88
>&2 echo " -e <glob> exclude files or directories (only for backup operation)"
9-
>&2 echo " -f force overwrite even if target volume is not empty during restore"
9+
>&2 echo " -f Allow backing up empty volume or restoring into non-empty volume, overwriting its contents"
1010
>&2 echo " -x <args> pass additional arguments to the Tar utility"
1111
>&2 echo " -v verbose"
1212
}
1313

1414
backup() {
15-
if [ -z "$(ls -A /volume)" ]; then
16-
>&2 echo "Volume is empty or missing, check if you specified a correct name"
17-
exit 1
15+
if [ -z "$FORCE" ] && [ -z "$(ls -A /volume)" ]; then
16+
>&2 echo "Volume is empty or missing, check if you specified a correct name"
17+
exit 1
1818
fi
1919

2020
if ! [ "$ARCHIVE" == "-" ]; then
@@ -71,10 +71,6 @@ while getopts "h?vfc:e:x:" OPTION; do
7171
TAROPTS+=(--exclude $OPTARG)
7272
;;
7373
f)
74-
if [ "$OPERATION" != "restore" ]; then
75-
usage
76-
exit 1
77-
fi
7874
FORCE=1
7975
;;
8076
v)

0 commit comments

Comments
 (0)