Backup and Restore are working.
This commit is contained in:
@ -58,10 +58,11 @@ void dropshell::autocomplete(const std::vector<std::string> &args)
|
||||
|
||||
if (args.size()==5) // we have the command and the server and the service. dropshell autocomplete command server service_name <command?>
|
||||
{
|
||||
std::string server_name = args[3];
|
||||
std::string service_name = args[4];
|
||||
if (cmd=="restore")
|
||||
{
|
||||
std::set<std::string> backups = dropshell::list_backups(service_name);
|
||||
std::set<std::string> backups = dropshell::list_backups(server_name, service_name);
|
||||
for (auto backup : backups)
|
||||
std::cout << backup << std::endl;
|
||||
return;
|
||||
|
@ -122,13 +122,20 @@ std::set<std::string> get_used_commands(const std::string &server_name, const st
|
||||
return commands;
|
||||
}
|
||||
|
||||
std::set<std::string> list_backups(const std::string &service_name)
|
||||
std::set<std::string> list_backups(const std::string &server_name, const std::string &service_name)
|
||||
{
|
||||
std::set<std::string> backups;
|
||||
|
||||
if (service_name.empty())
|
||||
if (server_name.empty() || service_name.empty())
|
||||
return backups;
|
||||
|
||||
// need to find the template for the service.
|
||||
ServiceInfo service_info = get_service_info(server_name, service_name);
|
||||
if (service_info.local_template_path.empty()) {
|
||||
std::cerr << "Error: Service not found: " << service_name << std::endl;
|
||||
return backups;
|
||||
}
|
||||
|
||||
std::string backups_dir = localpath::backups_path();
|
||||
if (backups_dir.empty())
|
||||
return backups;
|
||||
@ -136,7 +143,7 @@ std::set<std::string> list_backups(const std::string &service_name)
|
||||
if (fs::exists(backups_dir)) {
|
||||
for (const auto& entry : fs::directory_iterator(backups_dir)) {
|
||||
if (fs::is_regular_file(entry) && entry.path().extension() == ".tgz")
|
||||
if (entry.path().filename().string().find(service_name) != std::string::npos)
|
||||
if (entry.path().filename().string().find(service_info.template_name) != std::string::npos)
|
||||
{
|
||||
backups.insert(entry.path().filename().string());
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace dropshell {
|
||||
std::set<std::string> get_used_commands(const std::string& server_name, const std::string& service_name);
|
||||
|
||||
// list all backups for a given service (across all servers)
|
||||
std::set<std::string> list_backups(const std::string& service_name);
|
||||
std::set<std::string> list_backups(const std::string& server_name, const std::string& service_name);
|
||||
|
||||
bool create_service(const std::string& server_name, const std::string& template_name, const std::string& service_name, bool silent=false);
|
||||
} // namespace dropshell
|
||||
|
Reference in New Issue
Block a user