Commit b587245f authored by Natanael Copa's avatar Natanael Copa

lbu: implement LBU_BACKUPDIR

This allows users to do lbu commit into a dir without trying to mount
anything.
parent 66532283
...@@ -8,5 +8,9 @@ DEFAULT_CIPHER=aes-256-cbc ...@@ -8,5 +8,9 @@ DEFAULT_CIPHER=aes-256-cbc
# Can also be set to 'floppy' # Can also be set to 'floppy'
# LBU_MEDIA=usb # LBU_MEDIA=usb
# Set the LBU_BACKUPDIR variable in case you prefer to save the apkovls
# in a normal directory instead of mounting an external media.
# LBU_BACKUPDIR=/root/config-backups
# Uncomment below to let lbu make up to 3 backups # Uncomment below to let lbu make up to 3 backups
# BACKUP_LIMIT=3 # BACKUP_LIMIT=3
...@@ -160,10 +160,12 @@ list_delete() { ...@@ -160,10 +160,12 @@ list_delete() {
unpack_apkovl() { unpack_apkovl() {
local f="$(hostname).apkovl.tar.gz" local f="$(hostname).apkovl.tar.gz"
local dest="$1" local dest="$1"
local mnt="/media/$LBU_MEDIA" local mnt="${LBU_BACKUPDIR:-/media/$LBU_MEDIA}"
local count=0 local count=0
mkdir -p "$dest" mkdir -p "$dest"
mount_once "$mnt" if [ -n "$LBU_MEDIA" ]; then
mount_once "$mnt"
fi
if [ -n "$ENCRYPTION" ]; then if [ -n "$ENCRYPTION" ]; then
f="$f.$ENCRYPTION" f="$f.$ENCRYPTION"
fi fi
...@@ -389,7 +391,8 @@ Options: ...@@ -389,7 +391,8 @@ Options:
-v Verbose mode. -v Verbose mode.
The following values for <media> is supported: floppy usb The following values for <media> is supported: floppy usb
If <media> is not specified, the environment variable LBU_MEDIA will be used. If <media> is not specified, the environment variable LBU_BACKUPDIR or
LBU_MEDIA will be used. If LBU_BACKUPDIR is set, nothing will be mounted.
Password protection will use $DEFAULT_CIPHER encryption. Other ciphers can be Password protection will use $DEFAULT_CIPHER encryption. Other ciphers can be
used by setting the DEFAULT_CIPHER or ENCRYPTION environment variables. used by setting the DEFAULT_CIPHER or ENCRYPTION environment variables.
...@@ -412,14 +415,17 @@ cmd_commit() { ...@@ -412,14 +415,17 @@ cmd_commit() {
# turn on verbose mode if dryrun # turn on verbose mode if dryrun
[ -n "$DRYRUN" ] && VERBOSE="-v" [ -n "$DRYRUN" ] && VERBOSE="-v"
# find what media to use mnt="$LBU_BACKUPDIR"
media="${1:-$LBU_MEDIA}" if [ -z "$mnt" ]; then
[ -z "$media" ] && usage_commit # find what media to use
media="${1:-$LBU_MEDIA}"
[ -z "$media" ] && usage_commit
# mount media unles its already mounted # mount media unles its already mounted
mnt=/media/$media mnt=/media/$media
[ -d "$mnt" ] || usage [ -d "$mnt" ] || usage
mount_once_rw "$mnt" || die "failed to mount $mnt" mount_once_rw "$mnt" || die "failed to mount $mnt"
fi
# find the outfile # find the outfile
outfile="$mnt/$(hostname).apkovl.tar.gz" outfile="$mnt/$(hostname).apkovl.tar.gz"
...@@ -541,10 +547,12 @@ EOF ...@@ -541,10 +547,12 @@ EOF
cmd_listbackup() { cmd_listbackup() {
local media=${1:-"$LBU_MEDIA"} local media=${1:-"$LBU_MEDIA"}
local mnt="/media/$media" local mnt="${LBU_BACKUPDIR:-/media/$media}"
[ -z "$media" ] && usage_listbackup [ -z "$media" ] && [ -z "$LBU_BACKUPDIR" ] && usage_listbackup
mount_once "$mnt" || die "failed to mount $mnt" if [ -n "$media" ]; then
mount_once "$mnt" || die "failed to mount $mnt"
fi
ls -1 "$mnt"/*.[0-9][0-9]*[0-9][0-9].tar.gz* 2>/dev/null | sed 's:.*/::' ls -1 "$mnt"/*.[0-9][0-9]*[0-9][0-9].tar.gz* 2>/dev/null | sed 's:.*/::'
} }
...@@ -600,7 +608,7 @@ cmd_status() { ...@@ -600,7 +608,7 @@ cmd_status() {
return 0 return 0
fi fi
LBU_MEDIA=${1:-"$LBU_MEDIA"} LBU_MEDIA=${1:-"$LBU_MEDIA"}
[ -z "$LBU_MEDIA" ] && usage_status [ -z "$LBU_MEDIA" ] && [ -z "$LBU_BACKUPDIR" ] && usage_status
local tmp local tmp
init_tmpdir tmp init_tmpdir tmp
mkdir -p "$tmp/a" "$tmp/b" mkdir -p "$tmp/a" "$tmp/b"
...@@ -654,7 +662,7 @@ usage: $PROGRAM diff [<media>] ...@@ -654,7 +662,7 @@ usage: $PROGRAM diff [<media>]
cmd_diff() { cmd_diff() {
LBU_MEDIA=${1:-"$LBU_MEDIA"} LBU_MEDIA=${1:-"$LBU_MEDIA"}
[ -z "$LBU_MEDIA" ] && usage_diff [ -z "$LBU_MEDIA" ] && [ -z "$LBU_BACKUPDIR" ] && usage_diff
local tmp local tmp
init_tmpdir tmp init_tmpdir tmp
mkdir -p "$tmpdir/a" "$tmp/b" mkdir -p "$tmpdir/a" "$tmp/b"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment