Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
fl0id
arm monitoring
Commits
9c94e9ac
Commit
9c94e9ac
authored
Jan 18, 2018
by
CarlosEDP
Browse files
Added backup/restore scripts
parent
ed9c3b46
Changes
2
Hide whitespace changes
Inline
Side-by-side
backup_docker_volumes.sh
0 → 100755
View file @
9c94e9ac
#!/bin/bash
if
[[
$1
==
'-a'
]]
;
then
VOLUMES
=
$(
docker volume
ls
-q
)
elif
[[
$1
]]
;
then
if
`
docker volume
ls
-q
|grep
-w
$1
`
;
then
VOLUMES
=
$1
else
echo
"Volume
$1
does not exist."
exit
fi
else
echo
"No parameter passed, provide a volume name or '-a' to backup all volumes."
exit
fi
for
i
in
$VOLUMES
;
do
echo
Backup volume:
$i
export
DOCKER_VOLUME
=
$i
docker run
-d
\
--name
=
backup-
$i
\
--rm
\
-v
$DOCKER_VOLUME
:/
$DOCKER_VOLUME
:ro
\
-v
/mnt/1TB-WDred/Backups/:/backup
\
alpine
\
tar
-czpf
/backup/
$DOCKER_VOLUME
-
$(
date
+%Y%m%d_%H%M%S
)
.tar.gz
$DOCKER_VOLUME
done
restore_docker_volume.sh
0 → 100755
View file @
9c94e9ac
#!/bin/bash
if
[
$#
-eq
0
]
then
echo
"Please supply the backup file in the format: "
echo
"restore_docker_volume.sh /path/backup_file-20001212_000000.tar.gz"
echo
" "
exit
fi
pathToFile
=
$(
pwd
$(
dirname
$1
))
fileName
=
$(
basename
$1
)
VOLUME
=
$(
echo
$fileName
|
sed
's/\(.*\)-[0-9]*_[0-9]*\.tar\.gz/\1/'
)
# Check if docker volume exists
if
docker volume
ls
-q
|
grep
-q
$VOLUME
;
then
read
-p
"Volume already exists, overwrite all files? [yn] "
-n
1
-r
echo
# (optional) move to a new line
if
[[
!
$REPLY
=
~ ^[Yy]
$
]]
then
[[
"
$0
"
=
"
$BASH_SOURCE
"
]]
&&
exit
1
||
return
1
fi
else
echo
"Creating volume
$VOLUME
"
#docker volume create $VOLUME
fi
echo
Restore volume:
$VOLUME
docker run
-d
\
--name
=
restore-
$VOLUME
\
--rm
\
-v
$pathToFile
/:/source:ro
\
-v
$VOLUME
:/
$VOLUME
\
alpine
\
tar
zvxf /source/
$fileName
-C
/source
--strip-components
1
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment