This repository was archived by the owner on Aug 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime2dump.sh
More file actions
executable file
·163 lines (142 loc) · 2.81 KB
/
time2dump.sh
File metadata and controls
executable file
·163 lines (142 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
#
# time2dump
#
# Backup your databases
#
# MIT License
# Copyright (c) 2017-2022 Jean Prunneaux
#
# Version 1.5.0 (2022-02-19)
#
declare -r version=1.5.0
#
# Initialization
#
# get real path of the script
if [ "$(uname)" = Darwin ] ; then
# macOS which does not support readlink -f option
current_script=$(perl -e 'use Cwd "abs_path";print abs_path(shift)' "$0")
else
current_script=$(readlink -f "$0")
fi
# get directory of the current script
script_directory=$(dirname "$current_script")
# load libbash
source "$script_directory"/libbash/libbash.sh - > /dev/null
if [ $? != 0 ] ; then
echo >&2 "Error: cannot load libbash. Please add it to the '$script_directory/libbash' directory."
exit 1
fi
# load functions
source "$script_directory"/inc/functions.sh > /dev/null
if [ $? != 0 ] ; then
lb_error "Error: cannot load functions!"
exit 1
fi
# load commands
source "$script_directory"/inc/commands.sh > /dev/null
if [ $? != 0 ] ; then
lb_error "Error: cannot load commands!"
exit 1
fi
# load help
source "$script_directory"/inc/help.sh > /dev/null
if [ $? != 0 ] ; then
lb_error "Error: cannot load help!"
exit 1
fi
#
# Main Program
#
# get global options
while [ $# -gt 0 ] ; do
case $1 in
-c|--config)
# custom config path
if ! [ -f "$2" ] ; then
print_help global
exit 1
fi
config_file=$2
shift
;;
-D|--debug)
debug_mode=true
;;
-V|--version)
echo $version
exit
;;
-h|--help)
print_help global
exit
;;
-*)
print_help global
exit 1
;;
*)
break
;;
esac
shift # load next argument
done
lb_set_log_level INFO
lb_istrue $debug_mode && lb_set_log_level DEBUG
# load default config file if not specified
if [ -z "$config_file" ] ; then
# search config first in current directory, then in /etc
for f in "$script_directory"/config/time2dump.conf /etc/time2dump.conf ; do
if [ -f "$f" ] ; then
config_file=$f
break
fi
done
if [ -z "$config_file" ] ; then
lb_error "No config file found"
exit 1
fi
fi
# load config file
if ! lb_import_config -t "$script_directory"/config/time2dump.example.conf "$config_file" ; then
lb_error "Failed to load config"
exit 3
fi
# check config
check_config || exit 3
# load plugin
source "$script_directory"/plugins/"$db_protocol".sh > /dev/null
if [ $? != 0 ] ; then
lb_error "Error: cannot load plugin for protocol $db_protocol!"
exit 1
fi
# check plugin functions
for f in list_databases backup ; do
if ! lb_function_exists "_${db_protocol}_$f" ; then
lb_error "Error: plugin not compliant"
exit 1
fi
done
# backup is the default command
if [ $# = 0 ] ; then
command=backup
else
command=$1
shift
fi
# run command
case $command in
backup|history|rotate)
t2d_$command "$@"
clean_exit $?
;;
help)
print_help global
;;
*)
# unknown command
print_help global
exit 1
;;
esac