Tweak zfs options
This commit is contained in:
		
							parent
							
								
									33b1bd70f2
								
							
						
					
					
						commit
						8fc130d0a9
					
				
					 1 changed files with 24 additions and 13 deletions
				
			
		|  | @ -1,14 +1,15 @@ | |||
| #!/bin/bash | ||||
| # Create archived backups of zfs datasets, with support for incremental backups from automated snapshots. | ||||
| # Usage: backup-zfs-dataset [OPTIONS] <dataset> | ||||
| # Usage: backup-zfs-dataset [OPTIONS] <dataset> <destination> | ||||
| 
 | ||||
| usage() { | ||||
|     >&2 printf "Usage: %s [OPTIONS] <dataset>\n" "$0" | ||||
|     >&2 printf "Usage: %s [OPTIONS] [<dataset> <destination>]\n" "$0" | ||||
|     >&2 printf "Options:\n" | ||||
|     >&2 printf "\t-c  --compression-level <level>       \t Specify compression level (integer)\n" | ||||
|     >&2 printf "\t-s  --dataset <dataset name>          \t Specify dataset name\n" | ||||
|     >&2 printf "\t-d  --destination <path to directory> \t Specify destination\n" | ||||
|     >&2 printf "\t-m  --max-size <size>                 \t Specify maximum size of archive parts\n" | ||||
|     >&2 printf "\t-f  --force                           \t Force overwriting existing backups if the backup already exists\n" | ||||
|     exit "${1:-1}" | ||||
| } | ||||
| 
 | ||||
|  | @ -16,40 +17,44 @@ usage() { | |||
| 
 | ||||
| while [[ $# -gt 0 ]]; do | ||||
|     case "${1}" in | ||||
|         --compression_level | -c) | ||||
|         -c | --compression_level) | ||||
|             if ! [[ "${2}" =~ -[[:digit:]] ]]; then | ||||
|                 >&2 printf "Error: Invalid compression level: %s\n" "${2}" | ||||
|                 >&2 printf "Error: Invalid compression level: '%s'\n" "${2}" | ||||
|                 usage | ||||
|             fi | ||||
|             compression_level="${2}" | ||||
|             shift 2 | ||||
|             ;; | ||||
|         --dataset | -s) | ||||
|         -s | --dataset) | ||||
|             if ! [ -n "${2}" ]; then | ||||
|                 >&2 printf "Error: Invalid dataset: %s\n" "${2}" | ||||
|                 >&2 printf "Error: Invalid dataset: '%s'\n" "${2}" | ||||
|                 usage | ||||
|             fi | ||||
|             dataset="${2}" | ||||
|             shift 2 | ||||
|             ;; | ||||
|         --destination | -d) | ||||
|         -d | --destination) | ||||
|             if ! [ -d "${2}" ]; then | ||||
|                 >&2 printf "Error: Destination directory does not exist: %s\n" "${2}" | ||||
|                 >&2 printf "Error: Specified destination does not exist: '%s'\n" "${2}" | ||||
|                 usage | ||||
|             fi | ||||
|             destination="${2}" | ||||
|             shift 2 | ||||
|             ;; | ||||
|         --max-size | -m) | ||||
|         -m | --max-size) | ||||
|             if ! [[ "${2}" =~ [[:digit:]](K|M|G) ]]; then | ||||
|                 >&2 printf "Error: Invalid maximum size: %s\n" "${2}" | ||||
|                 >&2 printf "Error: Invalid maximum size: '%s'\n" "${2}" | ||||
|                 usage | ||||
|             fi | ||||
|             max_size="${2}" | ||||
|             shift 2 | ||||
|             ;; | ||||
|         -f | --force) | ||||
|             force_create_manual_backup=1 | ||||
|             shift 1 | ||||
|             ;; | ||||
|         *) | ||||
|             >&2 printf "Error: Invalid option: %s\n" "${1}" | ||||
|             >&2 printf "Error: Invalid option: '%s'\n" "${1}" | ||||
|             usage | ||||
|             ;; | ||||
|     esac | ||||
|  | @ -57,8 +62,14 @@ done | |||
| 
 | ||||
| # Check arguments. | ||||
| 
 | ||||
| if [ -z "${dataset}" ]; then | ||||
|     >&2 printf "Error: You need to specify a dataset.\n" | ||||
| if [[ -z "${dataset:=${1}}" || -z "${destination:=${2}}" ]]; then | ||||
|     >&2 printf "Error: You need to specify a dataset and a destination.\n" | ||||
|     usage | ||||
| elif [ -z "${dataset}" ]; then | ||||
|     >&2 printf "Error: Invalid dataset: '%s'\n" "${1}" | ||||
|     usage | ||||
| elif ! [ -d "${destination}" ]; then | ||||
|     >&2 printf "Error: Specified destination does not exist: '%s'\n" "${2}" | ||||
|     usage | ||||
| fi | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue