-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmirth_bash_backup.sh
51 lines (43 loc) · 1.42 KB
/
mirth_bash_backup.sh
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
#!/bin/bash
# Set these three vars as needed
backupPath="/home/backups/"
mccommand_to_run="/usr/local/bin/mccommand"
mccommand_config_properties="/usr/local/mirthconnect/conf/mirth-cli-config.properties" # you must edit the credentials in this file.
# Rest of script no changes needed
# the directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# the temp directory used, within $DIR
workdir=`mktemp -d -p "$DIR"` # created in current diretory
# check if tmp dir was created
if [[ ! "$workdir" ]]; then
echo "Could not create temp dir"
exit 1
fi
# deletes the temp directory - only if tmp dir was created
function cleanup {
rm -rf "$workdir"
}
# register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
# settings the paths
vDate=`date --date 'yesterday' +%Y-%m-%d`
# generating console command
echo exportcfg ${backupPath}mirth_backup-${vDate}.xml > ${workdir}/backup_cmds
# cat ${workdir}/backup_cmds
if [ ! -d ${backupPath} ]; then
echo "Backup Directory Not Found: ${backupPath}"
else
if [ -w ${backupPath} ] ; then
echo "Starting Backup"
${mccommand_to_run} -c ${mccommand_config_properties} -s ${workdir}/backup_cmds
else
echo "Cannot Write to Backup Directory: ${backupPath}"
fi
fi
if [ ! -f ${backupPath}mirth_backup-${vDate}.xml ]; then
echo "BACKUP FAILED"
else
echo "gzipping backup"
gzip -f ${backupPath}mirth_backup-${vDate}.xml
echo "BACKUP COMPLETED"
fi