Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Dockerfiles
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Picasoft
Technique
Dockerfiles
Commits
3c316997
Commit
3c316997
authored
7 years ago
by
Jerome Coste
Committed by
PICHOU Kyâne
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
pica-backup: In mysql and postgresql backup scripts, set backup folder as a variable
parent
2a0b9b4b
No related branches found
Branches containing commit
No related tags found
1 merge request
!5
CheckMK stable image
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pica-backup/mysql-run.sh
+8
-6
8 additions, 6 deletions
pica-backup/mysql-run.sh
pica-backup/postgres-run.sh
+8
-6
8 additions, 6 deletions
pica-backup/postgres-run.sh
with
16 additions
and
12 deletions
pica-backup/mysql-run.sh
+
8
−
6
View file @
3c316997
...
...
@@ -4,6 +4,8 @@ if [ "${MYSQL_ENV_MYSQL_PASS}" == "**Random**" ]; then
unset
MYSQL_ENV_MYSQL_PASS
fi
BACKUP_FOLDER
=
${
BACKUP_FOLDER
:-
"/backup/"
}
MYSQL_HOST
=
${
MYSQL_PORT_3306_TCP_ADDR
:-${
MYSQL_HOST
}}
MYSQL_HOST
=
${
MYSQL_PORT_1_3306_TCP_ADDR
:-${
MYSQL_HOST
}}
MYSQL_PORT
=
${
MYSQL_PORT_3306_TCP_PORT
:-${
MYSQL_PORT
}}
...
...
@@ -16,7 +18,7 @@ MYSQL_PASS=${MYSQL_PASS:-${MYSQL_ENV_MYSQL_PASS}}
[
-z
"
${
MYSQL_USER
}
"
]
&&
{
echo
"=> MYSQL_USER cannot be empty"
&&
exit
1
;
}
[
-z
"
${
MYSQL_PASS
}
"
]
&&
{
echo
"=> MYSQL_PASS cannot be empty"
&&
exit
1
;
}
BACKUP_CMD
=
"mysqldump -h
${
MYSQL_HOST
}
-P
${
MYSQL_PORT
}
-u
${
MYSQL_USER
}
-p
${
MYSQL_PASS
}
${
EXTRA_OPTS
}
${
MYSQL_DB
}
>
/backup/
"
'${BACKUP_NAME}'
BACKUP_CMD
=
"mysqldump -h
${
MYSQL_HOST
}
-P
${
MYSQL_PORT
}
-u
${
MYSQL_USER
}
-p
${
MYSQL_PASS
}
${
EXTRA_OPTS
}
${
MYSQL_DB
}
>
$BACKUP_FOLDER
"
'${BACKUP_NAME}'
echo
"=> Creating backup script"
rm
-f
/backup.sh
...
...
@@ -31,15 +33,15 @@ if ${BACKUP_CMD} ;then
echo " Backup succeeded"
else
echo " Backup failed"
rm -rf
/backup/
\$
{BACKUP_NAME}
rm -rf
$BACKUP_FOLDER
\$
{BACKUP_NAME}
fi
if [ -n "
\$
{MAX_BACKUPS}" ]; then
while [
\$
(ls
/backup
-N1 | wc -l) -gt
\$
{MAX_BACKUPS} ];
while [
\$
(ls
$BACKUP_FOLDER
-N1 | wc -l) -gt
\$
{MAX_BACKUPS} ];
do
BACKUP_TO_BE_DELETED=
\$
(ls
/backup
-N1 | sort | head -n 1)
BACKUP_TO_BE_DELETED=
\$
(ls
$BACKUP_FOLDER
-N1 | sort | head -n 1)
echo " Backup
\$
{BACKUP_TO_BE_DELETED} is deleted"
rm -rf
/backup/
\$
{BACKUP_TO_BE_DELETED}
rm -rf
$BACKUP_FOLDER
\$
{BACKUP_TO_BE_DELETED}
done
fi
echo "=> Backup done"
...
...
@@ -73,7 +75,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then
echo
"waiting database container..."
sleep
1
done
ls
-d
-1
/backup/
*
|
tail
-1
| xargs /restore.sh
ls
-d
-1
$BACKUP_FOLDER
*
|
tail
-1
| xargs /restore.sh
fi
echo
"
${
CRON_TIME
}
/backup.sh >> /mysql_backup.log 2>&1"
>
/crontab.conf
...
...
This diff is collapsed.
Click to expand it.
pica-backup/postgres-run.sh
+
8
−
6
View file @
3c316997
#!/bin/bash
BACKUP_FOLDER
=
${
BACKUP_FOLDER
:-
"/backup/"
}
[
-z
"
${
POSTGRES_HOST
}
"
]
&&
{
echo
"=> POSTGRES_HOST cannot be empty"
&&
exit
1
;
}
[
-z
"
${
POSTGRES_PORT
}
"
]
&&
{
echo
"=> POSTGRES_PORT cannot be empty"
&&
exit
1
;
}
[
-z
"
${
POSTGRES_USER
}
"
]
&&
{
echo
"=> POSTGRES_USER cannot be empty"
&&
exit
1
;
}
[
-z
"
${
POSTGRES_PASS
}
"
]
&&
{
echo
"=> POSTGRES_PASS cannot be empty"
&&
exit
1
;
}
[
-z
"
${
POSTGRES_DB
}
"
]
&&
{
echo
"=> POSTGRES_DB cannot be empty"
&&
exit
1
;
}
BACKUP_CMD
=
"pg_dump -w -c >
/backup/
"
'${BACKUP_NAME}'
BACKUP_CMD
=
"pg_dump -w -c >
$BACKUP_FOLDER
"
'${BACKUP_NAME}'
echo
"=> Creating backup script"
rm
-f
/backup.sh
...
...
@@ -26,15 +28,15 @@ if ${BACKUP_CMD} ;then
echo " Backup succeeded"
else
echo " Backup failed"
rm -rf
/backup/
\$
{BACKUP_NAME}
rm -rf
$BACKUP_FOLDER
\$
{BACKUP_NAME}
fi
if [ -n "
\$
{MAX_BACKUPS}" ]; then
while [
\$
(ls
/backup
-N1 | wc -l) -gt
\$
{MAX_BACKUPS} ];
while [
\$
(ls
$BACKUP_FOLDER
-N1 | wc -l) -gt
\$
{MAX_BACKUPS} ];
do
BACKUP_TO_BE_DELETED=
\$
(ls
/backup
-N1 | sort | head -n 1)
BACKUP_TO_BE_DELETED=
\$
(ls
$BACKUP_FOLDER
-N1 | sort | head -n 1)
echo " Backup
\$
{BACKUP_TO_BE_DELETED} is deleted"
rm -rf
/backup/
\$
{BACKUP_TO_BE_DELETED}
rm -rf
$BACKUP_FOLDER
\$
{BACKUP_TO_BE_DELETED}
done
fi
echo "=> Backup done"
...
...
@@ -74,7 +76,7 @@ elif [ -n "${INIT_RESTORE_LATEST}" ]; then
echo
"waiting database container..."
sleep
1
done
ls
-d
-1
/backup/
*
|
tail
-1
| xargs /restore.sh
ls
-d
-1
$BACKUP_FOLDER
*
|
tail
-1
| xargs /restore.sh
fi
echo
"
${
CRON_TIME
}
/backup.sh >> /postgres_backup.log 2>&1"
>
/crontab.conf
...
...
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