-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo_backup.sh
29 lines (24 loc) · 1012 Bytes
/
mongo_backup.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
#!/bin/bash
# Create a new folder to store the backup files
mkdir -p /backup/
echo "Creating backup folder ..."
# change the current directory to usr/bin folder of the container
cd /usr/bin
echo "💿 Backup started at $(date)"
# if mongodump command is successful echo success message else echo failure message
if mongodump --forceTableScan --uri $MONGODB_URI --username $MONGODB_USERNAME --password $MONGODB_PASSWORD --authenticationDatabase=admin --gzip --archive > /backup/dump_`date "+%Y-%m-%d-%T"`.gz
then
echo "Mongo Backup completed successfully at $(date)"
if s3cmd --access_key=$S3_ACCESS_KEY_ID --secret_key=$S3_SECRET_ACCESS_KEY --host=$S3_HOST --host-bucket=$S3_BUCKET --region=$S3_REGION sync /backup/ s3://$S3_BUCKET --recursive
then
echo "Uploaded to s3 bucket"
else
echo "Upload to s3 bucket failed at $(date)"
fi
else
echo "Backup failed at $(date)"
fi
echo "Cleaning up..."
# Clean up by removing the backup folder
rm -rf /backup/
echo "Done"