Bash script that uses the MongoDB Cloud Manager or Ops Manager REST API to trigger a restore of the latest snapshot and downloads the resulting tarball(s).
It is intended to have as few dependencies as possible and thus should work on most Linux and Mac OS environments without the need to install any additional software.
Works with Cloud Manager as well as Ops Manager 1.5 and above. Please report bugs via Github Issues or better yet, send fixes and patches via pull requests.
In the Cloud/Ops Manager web UI:
- Enable Public API for the Cloud/Ops Manager group to restore from
- Generate an API key
- Whitelist the IP address from which
mrestore
is run - Go to the URL of the replica set or cluster that you want to restore,
which should be in the following form:
https://cloud.mongodb.com/host/detail/XXXXXXX/YYYYYYY
- The group ID is
XXXXXXX
- The cluster ID is
YYYYYYY
- The group ID is
For details, refer to the REST API documentation.
$ ./mrestore.sh
Usage: mrestore.sh PARAMS [OPTIONS]
Required parameters:
--server-url URL Cloud/Ops Manager server URL (eg. https://cloud.mongodb.com)
--user USER Cloud/Ops Manager username, usually an email
--api-key API_KEY Cloud/Ops Manager API key (eg. xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
--group-id GROUP_ID Cloud/Ops Manager group ID (eg. 54c64146ae9fbe3d7f32c726)
--cluster-id CLUSTER_ID Cloud/Ops Manager cluster ID (eg. 54c641560cf294969781b5c3)
Options:
--out-dir DIRECTORY Download directory. Default: '.'
--timeout TIMEOUT_SECS Connection timeout. Default: 5
Miscellaneous:
--help Show this help message
$ ./mrestore.sh --server-url https://cloud.mongodb.com \
--user [email protected] \
--api-key 9d2fb094-108a-4c63-9ce6-5f79bbd8bd50 \
--group-id 54c64146ae9fbe3d7f32c726 \
--cluster-id 54c641560cf294969781b5c3
Cluster type : REPLICA_SET
Replica set name: mms-app
Latest snapshot ID: 54cc87420cf25152251c0353
Created on : 2015-01-31T07:40:23Z
Complete? : true
MongoDB version : 2.6.7
Data size : 1.4 MB
Storage size : 4.41 GB
File size : 7.49 GB (uncompressed)
Restore job ID: 54ccbe6e0cf2d19b280496b2
Waiting for restore job....
Status: FINISHED
Downloading restore tarball(s) to ./...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 12.3M 0 12.3M 0 0 400k 0 --:--:-- 0:00:31 --:--:-- 526k
Wrote to './54cc85f3504d16cb0bf4085d-mms-app-1422690023.tar.gz' (12.3 MB)
Note that any existing files with the same name will be overwritten.
$ ./mrestore.sh --server-url https://cloud.mongodb.com \
--user [email protected] \
--api-key 9d2fb094-108a-4c63-9ce6-5f79bbd8bd50 \
--group-id 54c64146ae9fbe3d7f32c726 \
--cluster-id 54c641560cf29493312346aa
Cluster type: SHARDED_REPLICA_SET
Cluster name: Cluster 3
Latest snapshot ID: 54cc9bc70cf2c0b4053c592b
Created on : 2015-01-31T09:08:56Z
Complete? : true
Part : 0
Type name : REPLICA_SET
Replica set name : shard01
MongoDB version : 2.6.7
Data size : 109.2 MB
Storage size : 126.1 MB
File size : 256.0 MB (uncompressed)
Part : 1
Type name : REPLICA_SET
Replica set name : shard02
MongoDB version : 2.6.7
Data size : 64.0 MB
Storage size : 92.3 MB
File size : 256.0 MB (uncompressed)
Part : 2
Type name : CONFIG_SERVER
MongoDB version : 2.6.7
Data size : 20 KB
Storage size : 20.1 MB
File size : 128.0 MB (uncompressed)
Batch ID: 54ccbed20cf2d19b280496cc
Waiting for restore job....
Status: FINISHED
Downloading restore tarball(s) to ./...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 130k 0 130k 0 0 208k 0 --:--:-- --:--:-- --:--:-- 208k
Wrote to './54cc85f3504d16cb0bf4085d-config-4f2e12eeb9c155a8c7118d78115134c2-1422695336.tar.gz' (132 KB)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 13.1M 0 13.1M 0 0 3416k 0 --:--:-- 0:00:03 --:--:-- 3416k
Wrote to './54cc85f3504d16cb0bf4085d-shard02-1422695336.tar.gz' (13.1 MB)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 21.9M 0 21.9M 0 0 3338k 0 --:--:-- 0:00:06 --:--:-- 3795k
Wrote to './54cc85f3504d16cb0bf4085d-shard01-1422695336.tar.gz' (21.9 MB)
Note that any existing files with the same name will be overwritten.