Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
7a0cd860
Commit
7a0cd860
authored
3 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add backup script
parent
9f6bd20b
No related branches found
No related tags found
1 merge request
!26
Eliminate scheduler
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backup.sh
+213
-0
213 additions, 0 deletions
backup.sh
backup.sh.banner
+0
-0
0 additions, 0 deletions
backup.sh.banner
with
213 additions
and
0 deletions
backup.sh
0 → 100755
+
213
−
0
View file @
7a0cd860
#!/bin/bash
# ================================================================================
#
# START BACKUP
#
# schedule backups.
# If backup time is reached then
# - the local dumps for all database types will be performed
# - transfer of data directories will be started
#
# This script is added as cron (see /etc/cron.d/)
#
# SYNTAX
# backup.sh [option]
#
# OPTIONS
# default: no parameter: start an incremental backup
# -f, --full force a full backup
# -d, --dryrun check date only; no run of a backup
#
# --------------------------------------------------------------------------------
# ah - Axel Hahn <axel.hahn@iml.unibe.ch>
#
# 2022-01-14 ah v1.0
# ================================================================================
.
"
$(
dirname
$0
)
"
/jobhelper.sh
typeset
-i
rcBackup
=
0
typeset
-i
rcTransfer
=
0
bStart
=
1
# --------------------------------------------------------------------------------
# functions
# --------------------------------------------------------------------------------
function
showHelp
(){
self
=
$(
basename
"
$0
"
)
cat
<<
EOFhelp
START A BACKUP
This script starts
- the database backups and creates dumps locally
- the file backup (using restic or dupliciity)
SYNTAX:
$self
[OPTIONS]
default: no parameter:
OPTIONS:
-d, --dryrun just show infos, do not start a backup
-h, --help Show this help
The following parameters force the backup type (if using duplicity):
-a, --auto force auto (repeat full backup if last full backup is older than ...)
This parameter requires a value like "1M" for 1 month
-f, --full force full backup (if supported)
-i, --inc force incrmenental backup
EOFhelp
}
# --------------------------------------------------------------------------------
# checks
# --------------------------------------------------------------------------------
# --- read schedulerdata
j_read
while
[
"$#"
-gt
0
]
;
do
case
"
$1
"
in
-h
|
-
\?
|
--help
)
echo
"Param: show help"
showHelp
exit
0
;;
-d
|
--dryrun
)
echo
"Param: setting to DRY RUN"
bStart
=
0
;;
-a
|
--auto
)
echo
"Param: setting to AUTO
$2
"
echo
"
$2
"
|
grep
"^[1-9][0-9]*[a-zA-Z]$"
2>/dev/null
if
[
$?
-ne
0
]
;
then
echo
"ERROR: the value after
$1
must be a number and a letter (for unit); i.e. 1M for 1 month"
exit
1
else
JOB_DOTODAY
=
1
JOBDEF_TYPE
=
auto
JOBDEF_AUTO
=
$2
bStart
=
1
shift
1
fi
;;
-f
|
--full
)
echo
"Param: setting to FULL"
JOB_DOTODAY
=
1
JOBDEF_TYPE
=
full
JOBDEF_AUTO
=
bStart
=
1
;;
-i
|
--inc
)
echo
"Param: setting to INC"
JOB_DOTODAY
=
1
JOBDEF_TYPE
=
inc
JOBDEF_AUTO
=
bStart
=
1
;;
*
)
echo
"ERROR: parameter [
$1
] is unknown"
showHelp
exit
1
esac
shift
1
done
JOBDEF_STARTTIME
=
$(
date
+%H%M
)
STORAGE_BIN
=
$(
_j_getvar
"
${
STORAGEFILE
}
"
"bin"
)
cat
<<
EOFbackupinfo
DEPRECATED: execution times:
$JOBDEF_INC
at `_j_getvar
${
JOBFILE
}
"start-time-inc"`
DEPRECATED: Full backup :
$JOBDEF_FULL
at `_j_getvar
${
JOBFILE
}
"start-time-full"`
DEPRECATED: do today =
$JOB_DOTODAY
Used Backup tool:
$STORAGE_BIN
type =
$JOBDEF_TYPE
$JOBDEF_AUTO
starttime =
$JOBDEF_STARTTIME
donefile =
$JOB_DONEFILE
EOFbackupinfo
j_requireUser
"root"
echo
"DEBUG
$0
... ABORT"
;
exit
1
# --------------------------------------------------------------------------------
if
[
$bStart
-eq
1
]
;
then
# ----- local dumps
echo
"INFO:
`
date
`
- starting backup ... type
$JOBDEF_TYPE
- time
$JOBDEF_STARTTIME
"
|
tee
-a
$JOB_LOGFILE
touch
"
${
JOB_DONEFILE
}
.01.START"
cat
$JOBFILE
>>
$JOB_LOGFILE
echo
"INFO:
`
date
`
- Making local backups ...
${
DIR_SELF
}
/localdump.sh ALL"
|
tee
-a
$JOB_LOGFILE
${
DIR_SELF
}
/localdump.sh ALL |
tee
-a
$JOB_LOGFILE
rcBackup
=
$?
echo
"INFO:
`
date
`
- local backups were finished"
|
tee
-a
$JOB_LOGFILE
sleep
2
# ----- transfer
if
[
-x
"
${
DIR_SELF
}
/transfer.sh"
]
;
then
# transfer files
echo
"INFO:
`
date
`
- Sending data to storage...
${
DIR_SELF
}
/transfer.sh
$JOBDEF_TYPE
"
|
tee
-a
$JOB_LOGFILE
touch
"
${
JOB_DONEFILE
}
.02.STARTTRANSFER"
${
DIR_SELF
}
/transfer.sh
$JOBDEF_TYPE
$JOBDEF_AUTO
2>&1 |
tee
-a
$JOB_LOGFILE
rcTransfer
=
$?
else
echo
"SKIP - transfer.sh not found; all files will be kept on local filesystem only"
|
tee
-a
$JOB_LOGFILE
fi
rcBackup
=
$rcBackup
+rcTransfer
echo
"INFO:
`
date
`
- DONE"
|
tee
-a
$JOB_LOGFILE
touch
"
${
JOB_DONEFILE
}
.03.DONE"
echo
echo
log
for
this executed job is
ls
-l
$JOB_LOGFILE
echo
echo
"INFO:
`
date
`
- cleanup logs"
echo
find
"
${
DIR_LOGS
}
"
-mtime
+28
-delete
-print
find
"
${
DIR_LOGS
}
"
-mtime
+28
-delete
-print
echo
echo
STATUS
$0
exit
with final returncode
rc
=
$rcBackup
|
tee
-a
$JOB_LOGFILE
echo
else
echo
"Nothing to do."
fi
# --------------------------------------------------------------------------------
exit
$rcBackup
# --------------------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
backup.sh.banner
0 → 100644
+
0
−
0
View file @
7a0cd860
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