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
fddbea58
Commit
fddbea58
authored
1 month ago
by
efer
Browse files
Options
Downloads
Patches
Plain Diff
"main" backup function
parent
d53e769e
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
+62
-48
62 additions, 48 deletions
comp-backup-install.sh
with
62 additions
and
48 deletions
comp-backup-install.sh
+
62
−
48
View file @
fddbea58
...
...
@@ -150,7 +150,7 @@ fi
# User Specific Variables
#
USER
=
$(
whoami
)
echo
-
n
"
\n
Enter your DTU username [
$USER
]: "
echo
-
e
"
\n
Enter your DTU username [
$USER
]: "
read
ANS
case
$ANS
in
""
)
...
...
@@ -167,7 +167,7 @@ if [ ! -d $FILE_DIR ]; then
mkdir
-p
$FILE_DIR
/old &>/dev/null
fi
echo
-e
"
\n
Looking for backup script..."
echo
"
Looking for backup script..."
if
[
-x
$BIN_DIR
/
$SCRIPTNAME
-
$RUSER
]
;
then
mv
$BIN_DIR
/
$SCRIPTNAME
-
$RUSER
$FILE_DIR
/old/
fi
...
...
@@ -409,7 +409,7 @@ 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 --log-level=INFO"
# OS version
if
[
$HOST_OS
=
'Darwin'
]
;
then
...
...
@@ -423,11 +423,19 @@ cat > $BIN_DIR/$SCRIPTNAME << EOF
#!/bin/bash
version=
$VERSION
TARGETNODE=
$TARGETNODE
LOG=
$LOG
LOGSHORT=
$LOGSHORT
CONF_DIR=
$CONF_DIR
SSHKEY=
$SSHKEY
FILTER=
$FILTER
OS_VER=
$OS_VER
# macOS specific fix
export LC_CTYPE=
# C
heck c
onnection
nc -z
$TARGETNODE
22 &>/dev/null
# Connection
check
nc -z
\
$
TARGETNODE 22 &>/dev/null
if [
\$
? -ne 0 ]; then
echo "No connection..."
exit 1
...
...
@@ -435,16 +443,25 @@ fi
# Log check
logcheck(){
lsize=
\$
(du
$LOG
|awk '{print
\$
1}')
lsize=
\$
(du
\
$
LOG|awk '{print
\$
1}')
if [
\$
lsize -gt 8192 ]; then
gzip -c
$LOG
>
$LOG
.
\$
(date +%Y-%m-%d).gz
echo >
$LOG
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)
fileList=
\$
(ssh -i
\
$
SSHKEY
$RUSER
@
\
$
TARGETNODE ls -1
$SNAPDIR
/ | grep pyznap)
if [ -z "
\$
fileList" ]; then
echo -e "
\e
[31mNo files found or failed to connect.
\e
[0m"
...
...
@@ -490,50 +507,33 @@ snapshots(){
echo -e "Next run these commands:
\n
"
echo -e "
$G_
source /tmp/rclone_snapshot
\n
rclone ls compbackup:
\n
$_N
"
echo -e "Example of copying a folder back:
\n
"
echo -e "
$G_
rclone copy compbackup:
${
RHOME
#?
}
/Myproject ~/Myproject_restore
$_N
"
echo -e "
$G_
rclone copy compbackup:
${
RHOME
#?
}
/Myproject ~/Myproject_restore
\n
$_N
"
}
# Use snapshot feature
while [
\$
# == 1 ]; do
case
\$
1 in
-r|restore)
snapshots
exit 0
;;
*)
echo "Unknown option
\$
1"
exit 1
;;
esac
done
if [ -f
$LOG
]; then
logcheck
fi
# Check rclone filter
FILTER=
$FILTER
defaultfilter() {
curl -s
\$
FILTER|grep -q
$SCRIPTNAME
if [
\$
? -eq 0 ]; then
# Check for default & user filter
if [ ! -f
$CONF_DIR
/filter.orig ]; then
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
$CONF_DIR
/filter.orig
if [ ! -f
$CONF_DIR
/filter ]; then
cp
$CONF_DIR
/filter.orig
$CONF_DIR
/filter
if [ ! -f
\
$
CONF_DIR/filter.orig ]; then
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
\
$
CONF_DIR/filter.orig
if [ ! -f
\
$
CONF_DIR/filter ]; then
cp
\
$
CONF_DIR/filter.orig
\
$
CONF_DIR/filter
fi
elif [ ! -f
$CONF_DIR
/filter ]; then
cp
$CONF_DIR
/filter.orig
$CONF_DIR
/filter
elif [ ! -f
\
$
CONF_DIR/filter ]; then
cp
\
$
CONF_DIR/filter.orig
\
$
CONF_DIR/filter
else
# Check for updated default filter
curl -s
\$
FILTER|sed s/user/
$RUSER
/g|diff
$CONF_DIR
/filter.orig - &>/dev/null
curl -s
\$
FILTER|sed s/user/
$RUSER
/g|diff
\
$
CONF_DIR/filter.orig - &>/dev/null
if [
\$
? -ne 0 ]; then
diff
$CONF_DIR
/filter
$CONF_DIR
/filter.orig &>/dev/null
diff
\
$
CONF_DIR/filter
\
$
CONF_DIR/filter.orig &>/dev/null
if [
\$
? -ne 0 ]; then
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
$CONF_DIR
/filter.orig
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
\
$
CONF_DIR/filter.orig
else
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
$CONF_DIR
/filter.orig
cp
$CONF_DIR
/filter.orig
$CONF_DIR
/filter
curl -s
\$
FILTER|sed s/user/
$RUSER
/g >
\
$
CONF_DIR/filter.orig
cp
\
$
CONF_DIR/filter.orig
\
$
CONF_DIR/filter
fi
fi
fi
...
...
@@ -541,10 +541,13 @@ else
echo "Cannot download filter template from server..."
fi
}
defaultfilter
# Backup command
run_backup(){
if [ -f
\$
LOG ]; then
logcheck
fi
$BACKUP_CMD
if [
\$
? -eq 0 ]; then
...
...
@@ -555,15 +558,26 @@ else
$NOTIFY1
fi
}
run_backup
# Log update
echo -e "Serial number:
$SERIALNO
" >
$LOGSHORT
echo -e "
$SCRIPTNAME
version:
\$
version" >>
$LOGSHORT
export OS_VER=
$OS_VER
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
# Main
if [
\$
# -eq 0 ]; then
defaultfilter
run_backup
logupdate
else
while [
\$
# -eq 1 ]; do
case
\$
1 in
-r|restore)
snapshots
exit 0
;;
*)
echo "Unknown option
\$
1"
exit 1
;;
esac
done
fi
EOF
chmod
+x
$BIN_DIR
/
$SCRIPTNAME
...
...
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