]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Backport parts of src/dird to community
authorKern Sibbald <kern@sibbald.com>
Sun, 1 Jul 2018 19:36:15 +0000 (21:36 +0200)
committerKern Sibbald <kern@sibbald.com>
Sun, 1 Jul 2018 19:36:15 +0000 (21:36 +0200)
bacula/src/cats/protos.h
bacula/src/cats/sql_delete.c
bacula/src/cats/sql_get.c
bacula/src/dird/dird_conf.h
bacula/src/dird/ua_cmds.c
bacula/src/dird/ua_dotcmds.c

index 39242564dc1a19fd2da975da8f47f6348bb27ad2..678d8a16e92787295b6ef65bec23728b74f3e185 100644 (file)
@@ -161,6 +161,8 @@ void bdb_free_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr);
            mdb->bdb_purge_media_record(jcr, mr)
 #define db_delete_snapshot_record(jcr, mdb, sr) \
            mdb->bdb_delete_snapshot_record(jcr, sr)
+#define db_delete_client_record(jcr, mdb, cr)         \
+           mdb->bdb_delete_client_record(jcr, cr)
 
 
 /* sql_find.c */
@@ -180,6 +182,8 @@ void bdb_free_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr);
 /* sql_get.c */
 #define db_get_volume_jobids(jcr, mdb, mr, lst) \
            mdb->bdb_get_volume_jobids(jcr, mr, lst)
+#define db_get_client_jobids(jcr, mdb, cr, lst) \
+           mdb->bdb_get_client_jobids(jcr, cr, lst)
 #define db_get_base_file_list(jcr, mdb, use_md5, result_handler, ctx) \
            mdb->bdb_get_base_file_list(jcr, use_md5, result_handler, ctx)
 #define db_get_path_record(jcr, mdb) \
index a46a3114a4ccec51fd6af189797de30e7c0dfec7..c93690fe44fbcd4d61c8fa4c3cd366d119508465 100644 (file)
@@ -236,4 +236,19 @@ int BDB::bdb_delete_snapshot_record(JCR *jcr, SNAPSHOT_DBR *sr)
    return 1;
 }
 
+/* Delete Client record */
+int BDB::bdb_delete_client_record(JCR *jcr, CLIENT_DBR *cr)
+{
+   bdb_lock();
+   if (cr->ClientId == 0 && !bdb_get_client_record(jcr, cr)) {
+      bdb_unlock();
+      return 0;
+   }
+
+   Mmsg(cmd, "DELETE FROM Client WHERE ClientId=%d", cr->ClientId);
+   bdb_sql_query(cmd, NULL, (void *)NULL);
+   bdb_unlock();
+   return 1;
+}
+
 #endif /* HAVE_SQLITE3 || HAVE_MYSQL || HAVE_POSTGRESQL */
index d2f26273c829cdfd7ffd619babeb154003d833fb..da6938f406af1baab22ff23b84fdb4113413f590 100644 (file)
@@ -1491,6 +1491,21 @@ bool BDB::bdb_get_volume_jobids(JCR *jcr,
    return ret;
 }
 
+/* Get JobIds associated with a client */
+bool BDB::bdb_get_client_jobids(JCR *jcr,
+                                CLIENT_DBR *cr, db_list_ctx *lst)
+{
+   char ed1[50];
+   bool ret = false;
+
+   bdb_lock();
+   Mmsg(cmd, "SELECT JobId FROM Job WHERE ClientId=%s",
+        edit_int64(cr->ClientId, ed1));
+   ret = bdb_sql_query(cmd, db_list_handler, lst);
+   bdb_unlock();
+   return ret;
+}
+
 /**
  * Get Snapshot Record
  *
index 40a69bb1ae65066d4928b7755acf09234a2c8afe..15bfb374b3c54a67aed82e21ade3507d7b6aad42 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2000-2017 Kern Sibbald
+   Copyright (C) 2000-2018 Kern Sibbald
 
    The original author of Bacula is Kern Sibbald, with contributions
    from many others, a complete list can be found in the file AUTHORS.
@@ -669,6 +669,7 @@ public:
    uint32_t MaxVolJobs;               /* Maximum jobs on the Volume */
    uint32_t MaxVolFiles;              /* Maximum files on the Volume */
    uint64_t MaxVolBytes;              /* Maximum bytes on the Volume */
+   uint64_t MaxPoolBytes;             /* Maximum bytes on the pool to create new vol */
    utime_t MigrationTime;             /* Time to migrate to next pool */
    uint64_t MigrationHighBytes;       /* When migration starts */
    uint64_t MigrationLowBytes;        /* When migration stops */
index 2c69f580201525a5b750f0baed13b4542e5fdd94..b9fd55c51d0f2349e52a52aa2159fe37d48ab4a1 100644 (file)
@@ -80,6 +80,7 @@ static void do_job_delete(UAContext *ua, JobId_t JobId);
 static int delete_volume(UAContext *ua);
 static int delete_pool(UAContext *ua);
 static void delete_job(UAContext *ua);
+static int delete_client(UAContext *ua);
 static void do_storage_cmd(UAContext *ua, const char *command);
 
 int qhelp_cmd(UAContext *ua, const char *cmd);
@@ -103,7 +104,7 @@ static struct cmdstruct commands[] = {                                      /* C
    NT_("[storage=<storage-name>] [volume=<vol>] [pool=<pool>] [allpools] [allfrompool] [mediatype=<type>] [drive=<number>] [slots=<number] \n"
        "\tstatus  | prune | list | upload | truncate"), true},
  { NT_("create"),     create_cmd,    _("Create DB Pool from resource"), NT_("pool=<pool-name>"),                    false},
- { NT_("delete"),     delete_cmd,    _("Delete volume, pool or job"), NT_("volume=<vol-name> | pool=<pool-name> | jobid=<id> | snapshot"), true},
+ { NT_("delete"),     delete_cmd,    _("Delete volume, pool, client or job"), NT_("volume=<vol-name> | pool=<pool-name> | jobid=<id> | client=<client-name> | snapshot"), true},
  { NT_("disable"),    disable_cmd,   _("Disable a job, attributes batch process"), NT_("job=<name> | client=<name> | schedule=<name> | storage=<name> | batch"),  true},
  { NT_("enable"),     enable_cmd,    _("Enable a job, attributes batch process"), NT_("job=<name> | client=<name> | schedule=<name> | storage=<name> | batch"),   true},
  { NT_("estimate"),   estimate_cmd,  _("Performs FileSet estimate, listing gives full listing"),
@@ -1564,6 +1565,9 @@ static int delete_cmd(UAContext *ua, const char *cmd)
    case 3:
       delete_snapshot(ua);
       return 1;
+   case 4:
+      delete_client(ua);
+      return 1;
    default:
       break;
    }
@@ -1585,6 +1589,9 @@ static int delete_cmd(UAContext *ua, const char *cmd)
    case 3:
       delete_snapshot(ua);
       return 1;
+   case 4:
+      delete_client(ua);
+      return 1;
    default:
       ua->warning_msg(_("Nothing done.\n"));
       break;
@@ -1713,6 +1720,59 @@ static int delete_pool(UAContext *ua)
    return 1;
 }
 
+/*
+ * Delete a client record from the database
+ */
+static int delete_client(UAContext *ua)
+{
+   CLIENT *client;
+   CLIENT_DBR  cr;
+   char buf[200];
+   db_list_ctx lst;
+
+   memset(&cr, 0, sizeof(cr));
+
+   if (!get_client_dbr(ua, &cr, 0)) {
+      return 1;
+   }
+
+   client = (CLIENT*) GetResWithName(R_CLIENT, cr.Name);
+
+   if (client) {
+      ua->error_msg(_("Unable to delete Client \"%s\", the resource is still defined in the configuration.\n"), cr.Name);
+      return 1;
+   }
+
+   if (!db_get_client_jobids(ua->jcr, ua->db, &cr, &lst)) {
+      ua->error_msg(_("Can't list jobs on this client\n"));
+      return 1;
+   }
+
+   if (find_arg(ua, "yes") > 0) {
+      ua->pint32_val = 1;
+
+   } else {
+      if (lst.count  == 0) {
+         bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Client \"%s\? (yes/no): "), cr.Name);
+      } else {
+         bsnprintf(buf, sizeof(buf), _("Are you sure you want to delete Client \"%s\" and purge %d job(s)? (yes/no): "), cr.Name, lst.count);
+      }
+      if (!get_yesno(ua, buf)) {
+         return 1;
+      }
+   }
+
+   if (ua->pint32_val) {
+      if (lst.count) {
+         ua->send_msg(_("Purging %d job(s).\n"), lst.count);
+         purge_jobs_from_catalog(ua, lst.list);
+      }
+      ua->send_msg(_("Deleting client \"%s\".\n"), cr.Name);
+      db_delete_client_record(ua->jcr, ua->db, &cr);
+   }
+   return 1;
+}
+
 int memory_cmd(UAContext *ua, const char *cmd)
 {
    garbage_collect_memory();
index 223735ca32c351e5537cc9c7f05e819edba4318f..a1656254707804f48df258cc8d67ec2e1fe84012 100644 (file)
@@ -180,7 +180,9 @@ bool do_a_dot_command(UAContext *ua)
          ok = (*commands[i].func)(ua, ua->cmd);   /* go execute command */
          if (ua->api) ua->signal(ok?BNET_CMD_OK:BNET_CMD_FAILED);
          ua->gui = gui;
-         found = ua->UA_sock->is_stop() ? false : true;
+         if (ua->UA_sock) {
+            found = ua->UA_sock->is_stop() ? false : true;
+         }
          break;
       }
    }