-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackupscript.ps1
157 lines (146 loc) · 3.79 KB
/
backupscript.ps1
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
###Backupscript
$datetime=get-date
$now=$datetime | get-date -Format yyyyMMdd_HHmm
#Start logging
start-transcript -path /root/$now
#Import ENV's
Import-CliXml /env-vars.clixml | % { Set-Item "env:$($_.Name)" $_.Value }
#Check if task is already running
if(test-path /running){
write-output "ERROR:Already running or previous job interrupted"
stop-transcript
. /reporting.ps1
exit
}
else {get-date > /running}
##Run pre script
if($ENV:OVERLAY){
. /overlayfsmount.ps1
}
if($ENV:CLEANBACKUPDIRBEFORE){
. /clean-backupdir.ps1
}
if($ENV:PRESCRIPT){
write-host "Running Pre-script from $($ENV:PRESCRIPT)"
. $ENV:PRESCRIPT
}
if($ENV:BW_CLIENTID){
. /bitwarden.ps1
}
if($ENV:PORTWARDEN_VAULTNAME){
. /portwarden.ps1
}
if($ENV:CIFS_UNC){
. /cifs.ps1
}
if($ENV:GCP_BUCKETNAME){
. /googlecloud.ps1
}
if($ENV:SCP_HOST){
. /scp.ps1
}
if($ENV:GITHUB_TOKEN){
"START GITHUB BACKUP"
. /github.ps1
}
if($ENV:ATLASSIANCLOUD_JIRABACKUP){
"START JIRA BACKUP"
. /jira-cloud.ps1
}
if($ENV:ATLASSIANCLOUD_CONFLUENCEBACKUP){
"START CONFLUENCE BACKUP"
. /confluence-cloud.ps1
}
if($ENV:OPSGENIE_APIKEY){
"START CONFLUENCE BACKUP"
. /opsgenie.ps1
}
if($ENV:INSTAGRAM_PROFILES){
"START INSTAGRAM BACKUP"
. /instagram.ps1
}
##Run backupjob
if($internalerrorflag){
write-error "Internal error detected, aborting job!"
}
elseif($ENV:PBS_PASSWORD -and $ENV:PBS_REPOSITORY -and $ENV:ARCHIVENAME){
#if username set, insert into repository string
if($ENV:PBS_USERNAME){
$ENV:PBS_REPOSITORY="$ENV:PBS_USERNAME@$ENV:PBS_REPOSITORY"
}
write-host "BACKUP STARTED $(get-date)"
#create args
#create 1 archive per item in the sourcefolder, or one global (default)
if($ENV:ARCHIVEPERITEM){
$backupargs="backup "
get-childitem $ENV:SOURCEDIR | foreach-object {
$backupargs=$backupargs + " " + $($_.name) + ".pxar:" + $($_.fullname)
}
}
elseif($ENV:BACKUPPERITEM){
get-childitem $ENV:SOURCEDIR | foreach-object -throttlelimit 10 -parallel {
$backupargs="backup"
$backupargs=$backupargs + " " + $($_.name) + ".pxar:" + $($_.fullname)
if($ENV:ENCRYPTIONKEY){
$backupargs+=" --keyfile $ENV:ENCRYPTIONKEY"
}
if($ENV:PBS_NAMESPACE){
$backupargs+=" --ns $ENV:PBS_NAMESPACE"
}
$backupargs+=" --backup-id $($_.name)"
Start-Process -Wait -Args $backupargs -FilePath proxmox-backup-client -nonewwindow -RedirectStandardOutput "/tmp/output-$($_.name).log" -RedirectStandardError "/tmp/error-$($_.name).log"
get-content "/tmp/output-$($_.name).log"
get-content "/tmp/error-$($_.name).log"
}
}
else{
$backupargs="backup $ENV:ARCHIVENAME.pxar:$ENV:SOURCEDIR"
}
if($ENV:ENCRYPTIONKEY){
$backupargs+=" --keyfile $ENV:ENCRYPTIONKEY"
}
if($ENV:PBS_NAMESPACE){
$backupargs+=" --ns $ENV:PBS_NAMESPACE"
}
#start the backup process
if($ENV:BACKUPPERITEM){}else{
Start-Process -Wait -Args $backupargs -FilePath proxmox-backup-client -RedirectStandardOutput /tmp/output.log -RedirectStandardError /tmp/error.log -nonewwindow
#Print log to transcript
get-content /tmp/output.log
get-content /tmp/error.log
}
write-host "BACKUP COMPLETE $(get-date)"
}
else {
write-host "MISSING VARIABLES"
}
##Run post script
if($ENV:POSTSCRIPT){
write-host "Running Post-script from $($ENV:POSTSCRIPT)"
. $ENV:POSTSCRIPT
}
if($ENV:CIFS_UNC){
umount /mnt/cifs
}
if($ENV:GITHUB_TOKEN){
. /post-github.ps1
}
if($ENV:ATLASSIANCLOUD_JIRABACKUP){
. /post-jira-cloud.ps1
}
if($ENV:ATLASSIANCLOUD_CONFLUENCEBACKUP){
. /post-confluence-cloud.ps1
}
if($ENV:CLEANBACKUPDIRAFTER){
. /post-clean-backupdir.ps1
}
if($ENV:OVERLAY){
. /post-overlayfsmount.ps1
}
#Remove flag to show that task is running
remove-item /running -force
stop-transcript
#Backup end for reporting
$datetimeend=get-date
#Process logs
. /reporting.ps1