-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.cpp
More file actions
118 lines (100 loc) · 4.38 KB
/
example_usage.cpp
File metadata and controls
118 lines (100 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Example usage of s3stor_lib
*
* This example demonstrates how to use the s3stor library in your own C++ application.
*/
#include "s3stor_lib.h"
#include <iostream>
#include <aws/core/Aws.h>
int main() {
// Initialize AWS SDK
Aws::SDKOptions options;
Aws::InitAPI(options);
{
// Configure S3 connection
s3stor::S3ProviderConfig config;
config.provider = "wasabi"; // or "aws"
config.bucket_name = "my-backup-bucket";
config.region = "us-east-1";
config.endpoint = "https://s3.us-east-1.wasabisys.com";
config.access_key_id = "YOUR_ACCESS_KEY";
config.secret_access_key = "YOUR_SECRET_KEY";
config.force_path_style = true; // Required for Wasabi
// Create S3Stor instance
std::cout << "Creating S3Stor instance..." << std::endl;
s3stor::S3Stor s3stor(config);
// Example 1: Sync a single file
std::cout << "\n=== Example 1: Sync a file ===" << std::endl;
if (s3stor.sync_file("test_in/example.txt", "test_in")) {
std::cout << "File synced successfully!" << std::endl;
} else {
std::cout << "File sync failed!" << std::endl;
}
// Example 2: Sync a directory
std::cout << "\n=== Example 2: Sync a directory ===" << std::endl;
if (s3stor.sync_dir("test_in")) {
std::cout << "Directory synced successfully!" << std::endl;
} else {
std::cout << "Directory sync failed!" << std::endl;
}
// Example 3: Create a snapshot
std::cout << "\n=== Example 3: Create a snapshot ===" << std::endl;
std::vector<std::string> files_to_snapshot = {"example.txt", "file1.txt"};
if (s3stor.create_snapshot("test_in", "my-snapshot-001", "myhost", files_to_snapshot)) {
std::cout << "Snapshot created successfully!" << std::endl;
} else {
std::cout << "Snapshot creation failed!" << std::endl;
}
// Example 4: List files in global catalog
std::cout << "\n=== Example 4: List global catalog ===" << std::endl;
s3stor.list_files();
// Example 5: List files in snapshot
std::cout << "\n=== Example 5: List snapshot files ===" << std::endl;
s3stor.list_snapshot_files("my-snapshot-001");
// Example 6: Get file map (show block structure)
std::cout << "\n=== Example 6: Display file map ===" << std::endl;
s3stor.get_file_map("", "example.txt"); // From global catalog
// Example 7: Restore a file from snapshot
std::cout << "\n=== Example 7: Restore file from snapshot ===" << std::endl;
if (s3stor.get_file("my-snapshot-001", "example.txt", "test_out/restored")) {
std::cout << "File restored successfully!" << std::endl;
} else {
std::cout << "File restoration failed!" << std::endl;
}
// Example 8: Delete a file from global catalog
std::cout << "\n=== Example 8: Delete file from catalog ===" << std::endl;
if (s3stor.delete_file("myhost", "old_file.txt")) {
std::cout << "File deleted successfully!" << std::endl;
} else {
std::cout << "File deletion failed or file not found!" << std::endl;
}
// Example 9: Delete a snapshot
std::cout << "\n=== Example 9: Delete snapshot ===" << std::endl;
if (s3stor.delete_snapshot("old-snapshot")) {
std::cout << "Snapshot deleted successfully!" << std::endl;
} else {
std::cout << "Snapshot deletion failed or snapshot not found!" << std::endl;
}
// Example 10: Cleanup unreferenced blocks
std::cout << "\n=== Example 10: Cleanup unreferenced blocks ===" << std::endl;
s3stor.cleanup_blocks("myhost");
std::cout << "\n=== All examples completed ===" << std::endl;
}
// Shutdown AWS SDK
Aws::ShutdownAPI(options);
return 0;
}
/*
* To build this example:
*
* g++ -std=c++17 example_usage.cpp s3stor_lib.cpp \
* -I/path/to/include \
* -laws-cpp-sdk-s3 -laws-cpp-sdk-core -laws-cpp-sdk-transfer \
* -lssl -lcrypto \
* -o example_usage
*
* Or add to CMakeLists.txt:
*
* add_executable(example_usage example_usage.cpp)
* target_link_libraries(example_usage PRIVATE s3stor_lib)
*/