Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
comp-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ITS
comp-backup
Commits
6e57c2a7
Commit
6e57c2a7
authored
1 month ago
by
efer
Browse files
Options
Downloads
Patches
Plain Diff
error info to logshort + logfile info in notifications + remove LOGSHORT var
parent
5279962a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
comp-backup-install.sh
+31
-23
31 additions, 23 deletions
comp-backup-install.sh
with
31 additions
and
23 deletions
comp-backup-install.sh
+
31
−
23
View file @
6e57c2a7
...
...
@@ -86,7 +86,7 @@ if [ $HOST_OS = 'Darwin' ]; then
UNIT_DIR
=
"
$H
/Library/LaunchAgents"
[
!
-d
$UNIT_DIR
]
&&
mkdir
-p
$UNIT_DIR
NOTIFY0
=
'osascript -e "display notification \"Backup done\" with title \"DTU Compute backup script\""'
NOTIFY1
=
'osascript -e "display notification \"Backup did not complete\" with title \"DTU Compute backup script\""'
NOTIFY1
=
'osascript -e "display notification \"Backup did not complete
- see $LOGNAME
\" with title \"DTU Compute backup script\""'
# Check for necessary programs
HOST_ARCH
=
$(
uname
-m
)
echo
-e
"
\n
Checking for dependencies..."
...
...
@@ -108,7 +108,7 @@ if [ $HOST_OS = 'Darwin' ]; then
elif
[
$HOST_OS
=
'Linux'
]
;
then
HOST
=
$(
hostname
-s
)
NOTIFY0
=
'notify-send -a "DTU Compute backup script" -i network-transmit "Backup done"'
NOTIFY1
=
'notify-send -a "DTU Compute backup script" -i network-error "Backup did not complete"'
NOTIFY1
=
'notify-send -a "DTU Compute backup script" -i network-error "Backup did not complete
- see $LOGNAME
"'
DISTRO
=
$(
grep
-Ew
"ID|ID_LIKE"
/etc/os-release |cut
-d
'='
-f
2
)
if
[[
${
DISTRO
[*]
}
=
~ debian
]]
||
[[
${
DISTRO
[*]
}
=
~ ubuntu
]]
;
then
PKGMAN
=
"apt"
...
...
@@ -427,12 +427,11 @@ echo -e "\nWriting backup script files..."
# Log vars
LOG
=
$FILE_DIR
/
$LOGNAME
LOGSHORT
=
$LOG
-short
LOGNAMESHORT
=
"logfile_short.txt"
SNAPDIR
=
".zfs/snapshot"
# Rclone command
BACKUP_CMD
=
"rclone sync / compbackup: --filter-from=
\$
CONF_DIR/filter --delete-excluded --delete-before --skip-links --log-file=
\$
LOG --log-level=INFO"
BACKUP_CMD
=
"rclone sync / compbackup: --filter-from=
\$
CONF_DIR/filter --delete-excluded --delete-before --skip-links --log-file=
\$
LOG
-last
--log-level=INFO"
# OS version
if
[
$HOST_OS
=
'Darwin'
]
;
then
...
...
@@ -448,7 +447,6 @@ version=$VERSION
TARGETNODE=
$TARGETNODE
LOG=
$LOG
LOGSHORT=
$LOGSHORT
CONF_DIR=
$CONF_DIR
SSHKEY=
$SSHKEY
FILTER=
$FILTER
...
...
@@ -464,24 +462,6 @@ if [ \$? -ne 0 ]; then
exit 1
fi
# Log check
logcheck(){
lsize=
\$
(du
\$
LOG|awk '{print
\$
1}')
if [
\$
lsize -gt 8192 ]; then
gzip -c
\$
LOG >
\$
LOG.
\$
(date +%Y-%m-%d).gz
echo >
\$
LOG
fi
}
# Log update
logupdate(){
echo -e "Serial number:
$SERIALNO
" >
\$
LOGSHORT
echo -e "
$SCRIPTNAME
version:
\$
version" >>
\$
LOGSHORT
echo -e "OS version:
\$
OS_VER" >>
\$
LOGSHORT
tail -n 6
\$
LOG >>
\$
LOGSHORT
rsync -a -e "ssh -i
\$
SSHKEY"
\$
LOGSHORT
$RUSER
@
\$
TARGETNODE:
$RHOME
/
$SCRIPTNAME
/
$HOST
/
$LOGNAMESHORT
}
# Get snapshots from backup server
snapshots(){
fileList=
\$
(ssh -i
\$
SSHKEY
$RUSER
@
\$
TARGETNODE ls -1
$SNAPDIR
/ | grep pyznap)
...
...
@@ -564,12 +544,23 @@ else
fi
}
# Log check
logcheck(){
lsize=
\$
(du
\$
LOG|awk '{print
\$
1}')
if [
\$
lsize -gt 8192 ]; then
gzip -c
\$
LOG >
\$
LOG.
\$
(date +%Y-%m-%d).gz
echo >
\$
LOG
fi
}
# Backup command
run_backup(){
if [ -f
\$
LOG ]; then
logcheck
fi
echo -e "
\n
#### BACKUP START:
\$
(date +%Y-%m-%d
\
%H:%M:%S)" >>
\$
LOG-short
$BACKUP_CMD
if [
\$
? -eq 0 ]; then
...
...
@@ -581,6 +572,23 @@ else
fi
}
# Log update
logupdate(){
echo -e "Serial number:
$SERIALNO
" >>
\$
LOG-short
echo -e "
$SCRIPTNAME
version:
\$
version" >>
\$
LOG-short
echo -e "OS version:
\$
OS_VER
\n
" >>
\$
LOG-short
if [[
\$
(grep -m1 ERROR
\$
LOG-last) ]]; then
grep ERROR
\$
LOG-last >>
\$
LOG-short
fi
LNO=
\$
( grep -n 'INFO'
\$
LOG-last | tail -1 | cut -d":" -f1 )
sed -n "
\$
LNO,
\$
p"
\$
LOG-last >>
\$
LOG-short
echo -e "#### BACKUP END:
\$
(date +%Y-%m-%d
\
%H:%M:%S)" >>
\$
LOG-short
cat
\$
LOG-last >>
\$
LOG
rm -f
\$
LOG-last
rsync -a -e "ssh -i
\$
SSHKEY"
\$
LOG-short
$RUSER
@
\$
TARGETNODE:
$RHOME
/
$SCRIPTNAME
/
$HOST
/
$LOGNAMESHORT
}
# Main
if [
\$
# -eq 0 ]; then
defaultfilter
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment