forked from lamw/ghettoVCB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghettoVCB-backup-crontab-setup.sh
executable file
·52 lines (42 loc) · 2.16 KB
/
ghettoVCB-backup-crontab-setup.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
52
# Author: Mart Verburg
# http://datamind.no
# Created Date: 2015-04-14
# published on GitHub.com in Datamind fork Datamind-dot-no/da-ghettoVCB
# forked from lamw/ghettoVCB
##
# ghettoVCB-backup-crontab-setup.sh
# Purpose: setup ghettoVCB cron schaduling functionality and persistance
# across ESXi restarts
# appends the ghettoVCB to the busybox bootstrap local init script
# will hardcode the SCRIPTPATH in the crontab-init script that is called from init.d
# Where we want the logs sent
LOGDIR=/vmfs/volumes/datastore1/log/da-ghettoVCB
# which file contains the custom ghettoVCB cronjobs
GHETTOCRONFILE=ghettoVCB-backup-crontab-entries.txt
INITDSCRIPT=/etc/rc.local.d/local.sh
##
## No need to edit anything below here
## -- unless you think you're more of a hacker like me ;-)
##
# Establish path to ghettoVCB dir
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
## hardcode the scriptpath into the crontab entries file
# use a sed in-place search and replace inside the file,
# use % as delimiter to avoid the slash in the path,
# match the path starting from leading / to the scriptname,
# and replace with the new path :-|)
sed -i "s%/.*ghettoVCB-backup-wrap.sh%$SCRIPTPATH/ghettoVCB-backup-wrap.sh%g" $SCRIPTPATH/$GHETTOCRONFILE
## Append the init.sh script to the InitD bootstrap routine for ESXi
# strip any ghettoVCB lines that may be in place beforehand
sed -i '/ghettoVCB/d' $INITDSCRIPT
## put line for our ghettoVCB crontab init shellscript to the ESXi initD script
# must be before the "exit 0" line found at the end if the default script in ESXi5.5
# hard to anchor this line anywhere, safest to put it right after the shebang at line
# number 2 using 2i in sed string, who knows what future updates may change in the default file
sed -i "2i$SCRIPTPATH/ghettoVCB-backup-crontab-init.sh" $INITDSCRIPT
## init.d should now be rigged to start our custom crontab init at next reboot
## run the init script right now as well to establish the new crontab and not wait for next reboot
$SCRIPTPATH/ghettoVCB-backup-crontab-init.sh
## To ensure that this is saved in the ESXi configuration, we need to manually initiate an ESXi backup by running:
/sbin/auto-backup.sh