Project

General

Profile

Revision 15ed27d8

Added by Julien Enselme over 9 years ago

Use getopts to print help and to parse script arguments.

View differences:

bin/d7-all-dump-individual.sh
1 1
#!/bin/sh
2 2

  
3
usage() {
4
    printf "d7-all-dump-individual.sh -m MODE\nRecognized mode are:\n\t%s\n\t%s\n" 'manunal' 'auto'
5
    printf "d7-all-dump-individual.sh -h prints this help message.\n"
6
}
7

  
8
mode=''
9
while getopts "hm:" opt; do
10
    case "${opt}" in
11
	h)
12
	    usage; exit 0;;
13
	m)
14
	    mode="$1";;
15
	:)
16
	    echo "Option -${OPTARG} requires an argument." >&2
17
	    usage >&2; exit 1;;
18
	\?)
19
	    usage >&2; exit 1;;
20
    esac
21
done
22
shift $((OPTIND-1))
23

  
24

  
3 25
. /home/assos/bin/scripts-config.sh
4 26
. scripts-utils.sh
5 27

  
6
help="# ARGS: auto or manual"
7

  
8
check_arguments "$#" 1 "$help"
9 28

  
10 29
current_date=$(date "+%Y-%m-%d-%Hh%Mm%Ss")
11 30

  
......
14 33
for dir in $(find . -maxdepth 1 -mindepth 1 -type d ! -name all | cut -c3-); do
15 34
    cd "${dir}"
16 35
    drush cc all
17
    if [ "$1" = 'auto' ] ; then
36
    if [ "${mode}" = 'auto' ] ; then
18 37
        drush sql-dump --result-file="${d7_dir_individual_auto_backup}/${dir}/${current_date}.${dir}.sql" --gzip
19 38
    else
20 39
        drush sql-dump --result-file="${d7_dir_individual_manual_backup}/${dir}/${current_date}.${dir}.sql" --gzip

Also available in: Unified diff