forked from kernelci/kernelci-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.sh
executable file
·44 lines (32 loc) · 855 Bytes
/
dump.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
while getopts "d:" option
do
case $option in
d) DUMP_FOLDER=$OPTARG;;
esac
done
# Dump timestamp
ts=$(date -u "+%Y%m%dT%H%M%S")
## Backup DB
# Name of the database to dump
DB="kernel-ci"
# Get db container
db=$(docker ps | grep mongo | awk '{print $1}')
if [ "$db" = "" ];then
echo "No mongo container running => exiting"
exit 1
fi
# Dump database
docker exec $db mongodump -d $DB --archive=/tmp/kernelci-$ts.gz --gzip
# Save on host (/var/lib/kernelci/dump)
docker cp $db:/tmp/kernelci-$ts.gz ${DUMP_FOLDER:-/tmp}
## Backup logs
# Run alpine container using logs volume
docker run \
--rm \
-v kernelci_kci:/tmp/logs \
-v ${DUMP_FOLDER:-/tmp}:/tmp/dump \
alpine tar -zcvf /tmp/dump/kernelci-logs-$ts.tar.gz /tmp/logs
echo
echo "=> database and log files will be saved in folder ${DUMP_FOLDER:-/tmp}"
echo