Teamwork Cloud 18.4 Documentation
- Created by Mimi Sari Kurnia, last modified on Jan 23, 2017
This page provides the instructions and the scripts required to back up and restore Cassandra database. These backup and restore scripts are same for both Windows and Linux Operating Systems. But on Windows, you should use the Cygwin tool to run the scripts (https://cygwin.com/install.html).
To make a backup data or to restore Cassandra database, you must add the Nodetool path to PATH. For detailed information, click the following link http://docs.datastax.com/en/cassandra/2.0/cassandra/operations/ops_backup_restore_c.html. You need to change the Cassandra username and password values in the scripts otherwise the default values will be used for authentication.
Backup and restore scripts
To backup and restore Cassandra database, you need the following files. Click the file to download it.
backup.sh
This script creates snapshots of Cassandra database. The script must run on the host running Cassandra and Cassandra must be running. The Cassandra bin directory or nodetool must be added to $PATH (not required if DataStax Cassandra is installed). The backup script preserves the database file permissions and owner.
$ ./backup.sh
Asks for Cassandra database and where to store the backup file, flushes data to disk, makes snapshots of Cassandra, then archives and puts them to a specified directory. After that it will clear the snapshots from the database.
$ ./backup.sh -dir CASSANDRA_DB_PATH
Asks Cassandra where to store the backup file, flushes data to disk, makes snapshots of Cassandra, then archives the snapshots from CASSANDRA_DB_PATH and puts them to a specified directory. After that it will clear the snapshots from the database.
$ ./backup.sh -dir CASSANDRA_DB_PATH -rf PUT_ARCHIVE_DIR
Flushes data to disk, makes snapshot of Cassandra, then archives snapshots from CASSANDRA_DB_PATH and puts them to PUT_ARCHIVE_DIR. After that it will clear the snapshots from the database.
restore-single_node.sh
This script should be run with 'su' on Linux and Cygwin console must be launched with the administrator privileges. This script restores data from the backup file. While restoring Cassandra, TWCloud server must be turned off. The script stops and starts Cassandra if needed. The backup script preserves the database file permissions and owner, and then restores backup on another machine with another user. Therefore, the file permissions must be changed manually otherwise Cassandra may not start. The following variables may be passed onto the script:
Variable | Description |
---|---|
commitlog_path | The path of commitlog files. They are removed when restoring database to prevent recovery of commits made earlier. DataStax recommends to store the commitlog files in a separate hard-disk for performance sake. |
cassandra_database | The Cassandra database path. It is used to clean existing database and restoring database from the recovery file. |
cassandra | The Cassandra installation path. It is the required parameter when Cassandra is launched not as service. |
service | The Boolean parameter indicating that Cassandra is started as a service. The default value is true so you need to set this variable to false when Cassandra is launched by the other script or manually. |
rf | The recovery file with the full path to it. |
On Linux, type the following line.
$ su ./restore-single_node.sh
On Windows, use Cygwin to run the scripts and type the following line.
$ ./restore-single_node.sh
The following are some other examples for Linux (just remove the 'su' parameter on Cygwin.
$ cassandra_database=<cassandra_database_path> commitlog_path=<cassandra_commitlog_path> rf=<backup_file_to_restore> su ./restore-single_node.sh $ cassandra_database=/var/lib/cassandra commitlog_path=/var/lib/cassandra/commitlog rf=/home/<user>/backups/cassandra_backup_2016.07.29.12.23.24.tar su ./restore-single_node.sh
Alternatively, you can set the parameters in the following order (note that the order matters).
$ su ./restore-single_node.sh -dir <cassandra_database_path> -commitlog <cassandra_commitlog_path> -rf <backup_file_to_restore> $ su ./restore-single_node.sh -dir /var/lib/cassandra -commitlog /var/lib/cassandra/commitlog -rf /home/<user>/backups/cassandra_backup_2016.07.29.12.23.24.tar
If Cassandra is not running as service, set the variable service to false. See the following example.
$ service=false su ./restore-single_node.sh
The following are the information you will be asked to enter.
- Please enter Cassandra database directory.
i.e. /var/lib/cassandra:
- Please enter Cassandra commitlog directory.
i.e. /var/lib/cassandra/commitlog:
- Please enter Cassandra home directory.
i.e. /opt/cassandra-2.2.5:
- Please enter backup file location.
i.e. /home/<user>/backups/:
Alternatively, you can set the parameters in the following order (note that the order matters).
$ su service=false ./restore-single_node.sh -dir <cassandra_database_path> -commitlog <cassandra_commitlog_path> -rf <backup_file_to_restore> -cassandra=<cassandra_home> $ su service=false ./restore-single_node.sh -dir /var/lib/cassandra -commitlog /var/lib/cassandra/commitlog -rf /home/<user>/backups/cassandra_backup_2016.07.29.12.23.24.tar -cassandra=/opt/apache-cassandra-2.2.5
- No labels