on mongodb backup

31
On MongoDB Backup 2014.05.02. 葉葉葉 William Yeh

Upload: william-yeh

Post on 15-Jan-2015

401 views

Category:

Software


1 download

DESCRIPTION

A gentle overview of MongoDB backup issues in a real sharding + replication production environment.

TRANSCRIPT

Page 1: On MongoDB backup

On MongoDB Backup

2014.05.02.葉秉哲

William Yeh

Page 2: On MongoDB backup

Why backup?

Availability vs. recovery

Cost is impacted by these decisions… How much data can you afford to lose? How long can you afford to be off-line?

Ref: “MongoDB Backups & Disaster Recovery”http://www.mongodb.com/presentations/webinar-backups-and-disaster-

recovery

2.

Page 3: On MongoDB backup

Tasks

3.

Backup Restore

One-time snapshot

Incremental

Page 4: On MongoDB backup

Two kinds of backup

One-time snapshot Capture a consistent snapshot at a specific

point in timeNot easy in a distributed zero-downtime

production system.

Incremental backup Capture differences since last one-time

snapshotOplog is N/A in MongoDB config servers (to be

discussed later)

4.

Page 5: On MongoDB backup

Cluster architecture in production

5.

Page 6: On MongoDB backup

How about MMS?MongoDB Management Service http://mms.mongodb.com

6.

Page 7: On MongoDB backup

$$

7.

Page 8: On MongoDB backup

8.

Backup Restore

One-time snapshot

Incremental

Page 9: On MongoDB backup

One-time snapshot steps

1. Stop balancer (mongos + config)

2. Take snapshot of config data

3. For each shard, take snapshot of one secondary

4. Re-start the balancer

5. Copy snapshots in steps 2 & 3

Ref: “Backup a Sharded Cluster with Filesystem Snapshots”http://bit.ly/1hqO1kj

9.

Page 10: On MongoDB backup

10.10.

1

2

3

4

5 Copy outCopy out

Take snapshotTake snapshot

Page 11: On MongoDB backup

#1#1Stop BalancerStop Balancer

11.

Page 12: On MongoDB backup

Stop balancer… Why?

“If MongoDB migrates a chunk during a backup, you can end with an inconsistent snapshot of your sharded cluster. Never run a backup while the balancer is active.”

Ref: “Disable Balancing During Backups”http://bit.ly/1rnRMfV

12.

Page 13: On MongoDB backup

#1: Stop balancer

var sleep_time_in_ms = 10000;

sh.setBalancerState(false);

while (sh.getBalancerState()

|| sh.isBalancerRunning()) {

sleep(sleep_time_in_ms);

}

// now the balancer is stopped…

Ref: “Disable Balancing During Backups”http://bit.ly/1rnRMfV

13.

Page 14: On MongoDB backup

#2#2Snapshot -Snapshot -config dataconfig data

14.

Page 15: On MongoDB backup

#3#3Snapshot -Snapshot -secondarysecondary

of each shardof each shard

15.

Page 16: On MongoDB backup

Snapshot the “dbpath”

Snapshoting step, almost the same: #2: Config server #3: Secondary

… but just one difference: “Never use db.fsyncLock() on config

databases.” Ref: “Backup a Sharded Cluster with Filesystem Snapshots”

http://bit.ly/1hqO1kj

16.

Page 17: On MongoDB backup

Snapshot approaches

“True” snapshot LVM, ZFS, Btrfs, etc. Cloud snapshot (EC2, GCE, etc.)

“Fake-and-slowwwww” dump mongodump fsyncLock() + tar + pigz Wordnik tool: https://github.com/wordnik/wordnik-oss

17.

Page 18: On MongoDB backup

Considerations for snapshot

Timing “Freeze” time period Archive (including compression &

transmission)

Storage efficiency Copy-on-write snapshot is better

18.

Page 19: On MongoDB backup

Snapshot: copy on write

Ref: “ 磁碟配額 (Quota) 與進階檔案系統管理”http://bit.ly/R67Yrd

19.

Page 20: On MongoDB backup

#4#4Re-start BalancerRe-start Balancer

20.

Page 21: On MongoDB backup

#4: Re-start balancer

sh.setBalancerState(true);

// now the balancer is re-started…

Ref: “Enable the Balancer”http://bit.ly/1hfKFl2

21.

Page 22: On MongoDB backup

#5#5Copy SnapshotCopy Snapshot

22.

Page 23: On MongoDB backup

Considerations for snapshot

Timing “Freeze” time Archive (including compression &

transmission)

Storage efficiency Copy-on-write snapshot is better

23.

Page 24: On MongoDB backup

24.

Backup Restore

One-time snapshot

Incremental

Page 25: On MongoDB backup

Restore approaches

“True” snapshot LVM, ZFS, Btrfs, etc. Cloud snapshot (EC2, GCE, etc.)

“Fake-and-slowwwww” dump mongorestore Daemon stop + untar Wordnik tool: https://github.com/wordnik/wordnik-oss

25.

Page 26: On MongoDB backup

26.

Backup Restore

One-time snapshot

Incremental

Page 27: On MongoDB backup

Oplog

Ordered list of write operations

27.

Page 28: On MongoDB backup

Oplog tools

Ready-to-use command line tools mongodump + mongorestore Wordnik tool: https://github.com/wordnik/wordnik-oss

Tayra tool:http://www.jroller.com/DhavalDalal/entry/tayra_an_incremental_backup_tool

mongosync:http://nosqldb.org/topic/5173d275cbce24580a033bd8

Still many others: https://github.com/search?q=mongo+oplog&type=Repositories

28.

Page 29: On MongoDB backup

Oplog in real-life

Replication lag Inspect it in real production environment!

Oplog is N/A in MongoDB config servers … Still need to deal with the balancer … Still need to use snapshot techniques

29.

Page 30: On MongoDB backup

Replication lag in real-life

30.

Page 31: On MongoDB backup

References

MongoDB: The Definitive Guide, 2/e MongoDB Manual

http://docs.mongodb.org/manual/administration/backup/

MongoDB Backups & Disaster Recovery http://www.mongodb.com/presentations/webinar-backups-and-disaster-recovery

Backup Strategies: Keeping Your Data Safe

http://www.mongodb.com/presentations/backup-strategies-keeping-your-data-safe

http://www.slideshare.net/fehguy/keeping-mongodb-data-safe

31.