Database Reference
In-Depth Information
Table 9-1 lists the variables you have to change to make this simple backup script work with your system.
Table 9-1. The Variables Used in the Local Datastore Backup Script
Variable
Description
MONGO_DBS
Leave this variable empty (“”) to back up all databases on the local server. Or you can place
a list of databases into it to back up selected databases ( "db1 db2 db3" ).
BACKUP_TMP
Set this variable to a temporary directory suitable for holding the dump files for the backup.
After the archive has been created, the temporary data used in this directory is deleted.
Be sure to choose a suitable directory that is relevant to using your script. For example, if you
are using the script to create backups in your local account, use ~/tmp ; if you are using it as a
system cronjob that runs under a system account, use /tmp . On an Amazon EC2 instance, you
should probably use /mnt/tmp , so that the folder is not created on the system root partition,
which is quite small.
BACKUP_DEST
This variable holds the destination folder for the backups, and individual folders will be
created below this folder. Again, place this directory at a point relevant to the way you use your
backup script.
MONGODUMP_BIN
Because your backup script may be running under an account that does not have a full
set of paths set up, it's wise to use this variable to specify the full path to this binary.
You can determine the appropriate path on your system by typing which mongodump into
a terminal window.
TAR_BIN
You use this variable to set the full path for the tar binary; use which tar in a terminal window
to determine this path.
You can now use this script to back up your databases; doing so will create a set of archival backups in the
specified BACKUP_DEST directory . The files created follow this naming format:
Database Name / database-YYYYMMDD-HHMM .tgz
For example, the following snippet shows the backup names for this chapter's test database:
Backups:$ tree
.
|-- blog
| |-- database-20100611-1144.tgz
| `-- database-20100611-1145.tgz
`-- all
|-- database-20100611-1210.tgz
|-- database-20100611-1221.tgz
|-- database-20100611-1222.tgz
|-- database-20100611-1224.tgz
`-- database-20100611-1233.tgz
Of course, you also need to install the script. If you want to run this script daily, just put it into /etc/cron.daily
and restart the cron service to make it active. This approach will work on most Linux distributions, such as Ubuntu,
Fedora, CentOS, and RedHat. If you want less frequent backups, just move the script to /etc/cron.weekly or /etc/
cron.monthly . For more frequent backups, you can use /etc/cron.hourly .
 
Search WWH ::




Custom Search