-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/bin/sh | ||
## Trigger mongodump on the server (given by $REMOTE) and copy dump here | ||
## and optionally to the cloud. | ||
## | ||
## You'll obviously first need to install mongodump on the server. | ||
## On Ubuntu: sudo apt-get install mongodb-clients | ||
## On Debian: sudo apt-get install mongo-tools | ||
|
||
## Where to ssh to do the mongodump | ||
HOSTNAME=comingle | ||
USERNAME=ubuntu | ||
#USERNAME=root | ||
SSH_REMOTE=$USERNAME@$HOSTNAME | ||
|
||
## Mongo collection to dump | ||
MONGO_COLLECTION=comingle | ||
|
||
## Local backup directory name | ||
BACKUP_DIR=comingle-backup | ||
|
||
## rclone is the recommended system to copy backups to a cloud service. | ||
## (acd_cli is another option, but it sadly was turned off by Amazon.) | ||
METHOD=rclone | ||
#METHOD=acd_cli | ||
|
||
## 1 for a separate backup for each day; 0 to overwrite the backup each time | ||
DATE_IN_DIR=0 | ||
if [ "$DATE_IN_DIR" -eq 1 ] | ||
then | ||
datedir=/`date +%Y-%m-%d` | ||
else | ||
datedir= | ||
fi | ||
|
||
## Set up an rclone remote with this name using `rclone config`. | ||
CLOUD_REMOTE=coauthor-backup | ||
#CLOUD_REMOTE=comingle-backup | ||
|
||
## Directory to create on cloud remote. | ||
CLOUD_DIR="comingle-backup$datedir" | ||
|
||
cd "`dirname "$0"`" | ||
echo \* mongodump | ||
ssh "$SSH_REMOTE" mongodump --db "$MONGO_COLLECTION" --gzip | ||
echo \* rsync | ||
rsync -e ssh -a "$SSH_REMOTE:dump/$MONGO_COLLECTION/" "$BACKUP_DIR/" | ||
|
||
echo \* $METHOD | ||
|
||
case $METHOD in | ||
|
||
rclone) | ||
if rclone --retries 10 copy "$BACKUP_DIR" $CLOUD_REMOTE:$CLOUD_DIR | ||
then | ||
echo SUCCESS\!\! | ||
else | ||
echo FAILURE... | ||
fi | ||
;; | ||
|
||
acd_cli) | ||
count=0 | ||
limit=20 | ||
acd_cli sync | ||
acd_cli mkdir /$CLOUD_DIR | ||
while ! acd_cli ul -q -o "$BACKUP_DIR"/* /${CLOUD_DIR} | ||
do | ||
echo Trying again... $count | ||
acd_cli sync | ||
count=`expr $count + 1` | ||
if [ $count -gt $limit ] | ||
then | ||
break | ||
fi | ||
done | ||
if [ $count -le $limit ] | ||
then | ||
echo SUCCESS\!\! | ||
fi | ||
;; | ||
|
||
esac |