2017-07-15 11:26:33 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2017-07-15 12:03:38 +02:00
|
|
|
# execute script in its location folder
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
2017-05-28 00:51:23 +02:00
|
|
|
# array of available collection names
|
2019-02-10 20:08:15 +01:00
|
|
|
col=(app_user awarding campaign decoration logBudget logFlag logKill logPlayerCount logPoints logRespawn logRevive logServerFps logTransport logVehicle player promotion rank squad user war)
|
2017-05-27 23:35:31 +02:00
|
|
|
|
2017-08-27 15:33:04 +02:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
DATE=$(date '+%Y-%m-%d')
|
2017-08-27 15:50:28 +02:00
|
|
|
mkdir -p ${DATE}/resource
|
2019-02-04 17:29:16 +01:00
|
|
|
cp -R ../server/resource/ ${DATE}/
|
2017-08-27 15:33:04 +02:00
|
|
|
else
|
|
|
|
DATE=${1}
|
|
|
|
tar -xzf ${DATE}.tar.gz
|
2019-02-04 17:29:16 +01:00
|
|
|
rm -rf ../server/resource
|
|
|
|
cp -Rv ${DATE}/resource ../server/
|
2017-08-27 15:33:04 +02:00
|
|
|
fi
|
|
|
|
|
2017-05-27 23:35:31 +02:00
|
|
|
for i in "${col[@]}"
|
|
|
|
do
|
2017-05-28 00:51:23 +02:00
|
|
|
# provide date for restore process, if data import is needed
|
|
|
|
if [ -z "$1" ]
|
2017-05-27 23:35:31 +02:00
|
|
|
then
|
2018-02-04 15:58:28 +01:00
|
|
|
(>&2 echo -e "$(date "+%Y-%m-%dT%T.%3N%z")\tTable: ${i}")
|
2017-08-26 18:35:00 +02:00
|
|
|
mongoexport --db cc --collection $i --out ${DATE}/collections/${i}.json;
|
2017-05-27 23:35:31 +02:00
|
|
|
else
|
2017-05-28 00:51:23 +02:00
|
|
|
mongoimport --db cc --collection $i --drop --file ${1}/collections/${i}.json
|
2017-05-27 23:35:31 +02:00
|
|
|
fi
|
|
|
|
done
|
2017-08-27 15:33:04 +02:00
|
|
|
|
2017-10-12 08:25:44 +02:00
|
|
|
if [ $(ls -lt --hide=backup.sh | wc -l) -gt 14 ]; then
|
2017-09-05 15:48:15 +02:00
|
|
|
$(rm "$(ls -t --hide=backup.sh | tail -1)")
|
|
|
|
fi
|
|
|
|
|
2017-08-27 15:33:04 +02:00
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
tar -zcf ${DATE}.tar.gz ${DATE}
|
2017-10-12 08:25:44 +02:00
|
|
|
rm -rf ${DATE}
|
|
|
|
elif [[ $1 =~ ^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$ ]]
|
2017-10-09 19:20:25 +02:00
|
|
|
then
|
|
|
|
rm -rf ${DATE}
|
|
|
|
fi
|