This topic describes how to use the snapshot feature of OSS-HDFS (JindoFS).
Background information
OSS-HDFS (JindoFS) is a new storage service based on Object Storage Service (OSS). OSS-HDFS is compatible with Hadoop Distributed File System (HDFS) API and supports directories of multiple levels. You can use JindoSDK V4.x to access the OSS-HDFS service. You can use the snapshot feature of OSS-HDFS in the same manner as the snapshot feature of HDFS. This topic describes the common operations that you need to perform when you use the snapshot feature of OSS-HDFS.
Limits
Only JindoData V4.0.0 and later support this feature.
Enable the snapshot feature
hdfs dfs -mkdir oss://oss-dfs-test.<Endpoint>/TestSnapshotjindo admin -allowSnapshot -dlsUri <path>jindo admin -allowSnapshot -dlsUri oss://oss-dfs-test.<Endpoint>/TestSnapshotCreate a snapshot
hdfs dfs -createSnapshot <path> [<snapshotName>]For example, you can create a snapshot named S1 for the TestSnapshot directory to save the status of the directory at the point in time when the snapshot is created. # Run the following commands to create subdirectories and files in the TestSnapshot directory for testing:
hdfs dfs -mkdir oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir1
hdfs dfs -mkdir oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir2
hdfs dfs -touchz oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir1/file1
hdfs dfs -touchz oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir3/file2
# Run the following command to create a snapshot named S1 for the TestSnapshot directory:
hdfs dfs -createSnapshot oss://oss-dfs-test.<Endpoint>/TestSnapshot S1Access directories and files in a snapshot
Path format of a directory or file in a snapshot
<snapshotRoot>/.snapshot/<snapshotName>/<actual subPath>In the preceding path, the snapshotRoot parameter specifies the root directory of snapshots. The root directory is the path specified for the dlsUri parameter in the command for enabling the snapshot feature. The snapshotName parameter specifies the name of a snapshot. The subsequent path is the path of the directory or file to be accessed in the root directory of snapshots. In this example, the root directory is TestSnapshot. hdfs dfs -ls oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir1hdfs dfs -ls oss://oss-dfs-test.<Endpoint>/TestSnapshot/.snapshot/S1/dir1In the preceding command, .snapshot/S1 specifies the snapshot that you want to access. Use a snapshot to restore data
The snapshot feature can be used to back up and restore data. You can use a snapshot to restore important data if the data is accidentally deleted. You can access data in a snapshot by using the path format described in the previous section, and then restore the data based on your business requirements.
For example, you accidentally deleted the dir1 directory from the TestSnapshot directory by running the hdfs dfs -rm -r oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir1 command. To restore the deleted directory, perform the following steps:
- Use the S1 snapshot that you created for the TestSnapshot directory to restore the deleted directory.
hdfs dfs -cp oss://oss-dfs-test.<Endpoint>/TestSnapshot/.snapshot/S1/dir1 oss://oss-dfs-test.<Endpoint>/TestSnapshot - Check whether the directory is restored.
If the /TestSnapshot/dir1 directory that is accidentally deleted and the files in the directory can be viewed, the data is restored.hdfs dfs -ls oss://oss-dfs-test.<Endpoint>/TestSnapshot/dir1
Rename a snapshot
hdfs dfs -renameSnapshot <path> <oldName> <newName>For example, you can run the following command to rename the S1 snapshot S100: hdfs dfs -renameSnapshot oss://oss-dfs-test.<Endpoint>/TestSnapshot S1 S100Delete a snapshot
hdfs dfs -deleteSnapshot <path> <snapshotName>For example, you can run the following command to delete the S100 snapshot that you obtained by creating and renaming the S1 snapshot: hdfs dfs -deleteSnapshot oss://oss-dfs-test.<Endpoint>/TestSnapshot S100Disable the snapshot feature
jindo admin -disallowSnapshot -dlsUri <path>jindo admin -disallowSnapshot -dlsUri oss://oss-dfs-test.<Endpoint>/TestSnapshotCompare snapshots
jindo dls -snapshotDiff -dlsUri <uri> -fromSnapshot <fromSnapshot> -toSnapshot <toSnapshot>