Skip to content
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

enable custom config file #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Usage: zfsbud [OPTION]... SOURCE/DATASET/PATH [SOURCE/DATASET/PATH2...]
-r, --remove-old remove old snapshots according to the policy defined in the configuration file
-d, --dry-run show output without making actual changes
-p, --snapshot-prefix <prefix> use a snapshot prefix other than the one defined in the configuration file
-C, --custom-config </path/to/file> custom config file
-v, --verbose increase verbosity
-l, --log log to user's home directory
-L, --log-path </path/to/file> provide path to log file (implies --log)
Expand Down
31 changes: 26 additions & 5 deletions zfsbud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@ config_read_file() {
}

config_get() {
working_dir="$(dirname "$(readlink -f "$0")")"
val="$(config_read_file $working_dir/zfsbud.conf "${1}")";
if [ "${val}" = "__UNDEFINED__" ]; then
val="$(config_read_file $working_dir/default.zfsbud.conf "${1}")";
if [ -v custom_config ]; then
val="$(config_read_file "$custom_config_path" "${1}")";
if [ "${val}" = "__UNDEFINED__" ]; then
die "Custom config configuration file $custom_config_path is missing or corrupt."
fi
else
working_dir="$(dirname "$(readlink -f "$0")")"
val="$(config_read_file $working_dir/zfsbud.conf "${1}")";
if [ "${val}" = "__UNDEFINED__" ]; then
die "Default configuration file 'default.zfsbud.conf' is missing or corrupt."
val="$(config_read_file $working_dir/default.zfsbud.conf "${1}")";
if [ "${val}" = "__UNDEFINED__" ]; then
die "Default configuration file 'default.zfsbud.conf' is missing or corrupt."
fi
fi
fi
printf -- "%s" "${val}";
Expand All @@ -37,6 +44,7 @@ help() {
echo " -r, --remove-old remove all but the most recent, the last common (if sending), 8 daily, 5 weekly, 13 monthly and 6 yearly source snapshots"
echo " -d, --dry-run show output without making actual changes"
echo " -p, --snapshot-prefix <prefix> use a snapshot prefix other than 'zfsbud_'"
echo " -C, --custom-config </path/to/file> custom config file"
echo " -v, --verbose increase verbosity"
echo " -l, --log log to user's home directory"
echo " -L, --log-path </path/to/file> provide path to log file (implies --log)"
Expand Down Expand Up @@ -65,8 +73,19 @@ for arg in "$@"; do
fi
shift
;;
-C | --custom-config)
if [ "$2" ] && [[ $2 != -* ]]; then
custom_config=1
custom_config_path=$2
shift
shift
else
die "--custom-config|-C requires a path string as argument."
fi
;;
-p | --snapshot-prefix)
if [ "$2" ] && [[ $2 != -* ]]; then
custom_snapshot_prefix=1
snapshot_prefix=$2
shift
shift
Expand Down Expand Up @@ -139,6 +158,8 @@ for arg in "$@"; do
esac
done

[ -v custom_config ] && [ ! -v custom_snapshot_prefix ] && snapshot_prefix=$(config_get default_snapshot_prefix)

dataset_exists() {
if [ -v remote_shell ]; then
$remote_shell "zfs list -H -o name" | grep -qx "$1" && return 0
Expand Down