Restoring Data from snapshot-
Steps-
1. go to the Cassandra Shell
cqlsh
2. use the keyspace
use admatic;
3. display the emp table
select * from emp;
4. as we previously took the snapshot of the data let's truncate it.
5. if not backed-up, take snapshot first
6. truncate the table called emp
truncate emp;
7. verify that the table has been truncated
select * from emp;
Output
cqlsh:cycling> select * from cyclist_name;
id | firstname | lastname
----+-----------+----------
(0 rows)
cqlsh:cycling>
8. the location of snapshots is as follows
general
/var/lib/cassandra/data/<keyspace-name>/<table-name>
eg
/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981
9. Copy all the files under the snapshot directory to the data directory of the table 'emp'
cd /var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981
sudo cp /var/lib/cassandra/data/keyspace1/emp-20e70b2030d511e8bdf32b06aa808981/snapshots/1522060378404/* .
sudo cp /var/lib/cassandra/data/keyspace1/standard1-c76b7fa0329f11e89f4ef1ab1be42c89/snapshots/truncated-1522260086121-standard1/* .
10. Run the nodetool refresh command so Cassandra knows that the data files are restored now
general
nodetool refresh <keyspace-name> <table-name>
eg
nodetool refresh admatic emp
- verify if the table has been restored
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> use admatic;
cqlsh:admatic> select * from emp;
emp_id | emp_city | emp_email | emp_name | emp_phone | emp_sal
--------+-----------+-----------+----------+------------+---------
1 | Hyderabad | null | ram | 9848022338 | 50000
2 | null | null | robin | 9848022339 | 50000
4 | Pune | null | rajeev | 9848022331 | 30000
3 | null | null | null | null | 50000
(4 rows)
cqlsh:admatic>
Log-Data
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic$ ls
emp-20e70b2030d511e8bdf32b06aa808981
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic$ cd c*
bash: cd: c*: No such file or directory
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic$ cd e*
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ ls
backups mc-1-big-Filter.db mc-1-big-TOC.txt mc-2-big-Filter.db mc-2-big-TOC.txt
mc-1-big-CompressionInfo.db mc-1-big-Index.db mc-2-big-CompressionInfo.db mc-2-big-Index.db snapshots
mc-1-big-Data.db mc-1-big-Statistics.db mc-2-big-Data.db mc-2-big-Statistics.db
mc-1-big-Digest.crc32 mc-1-big-Summary.db mc-2-big-Digest.crc32 mc-2-big-Summary.db
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> use admatic
... ;
cqlsh:admatic> describe tables;
emp
cqlsh:admatic> truncate emp;
cqlsh:admatic> select * from emp;
emp_id | emp_city | emp_email | emp_name | emp_phone | emp_sal
--------+----------+-----------+----------+-----------+---------
(0 rows)
cqlsh:admatic>
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ ls
backups snapshots
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ cd snapshots/
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots$ ls
1522060378404 26-02-18 26-03-18 truncated-1522063178353-emp
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots$ cd 1522060378404/
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots/1522060378404$ ls
manifest.json mc-1-big-Filter.db mc-1-big-TOC.txt mc-2-big-Filter.db mc-2-big-TOC.txt
mc-1-big-CompressionInfo.db mc-1-big-Index.db mc-2-big-CompressionInfo.db mc-2-big-Index.db schema.cql
mc-1-big-Data.db mc-1-big-Statistics.db mc-2-big-Data.db mc-2-big-Statistics.db
mc-1-big-Digest.crc32 mc-1-big-Summary.db mc-2-big-Digest.crc32 mc-2-big-Summary.db
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots/1522060378404$ cd ..
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots$ cd ..
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ clear
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ sudo cp /var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981/snapshots/1522060378404/* .
[sudo] password for admatic:
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ nodetool refresh admatic emp
admatic@admatic-VirtualBox:/var/lib/cassandra/data/admatic/emp-20e70b2030d511e8bdf32b06aa808981$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> use admatic;
cqlsh:admatic> select * from emp;
emp_id | emp_city | emp_email | emp_name | emp_phone | emp_sal
--------+-----------+-----------+----------+------------+---------
1 | Hyderabad | null | ram | 9848022338 | 50000
2 | null | null | robin | 9848022339 | 50000
4 | Pune | null | rajeev | 9848022331 | 30000
3 | null | null | null | null | 50000
(4 rows)
cqlsh:admatic>