]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/restore_mediatype_storage_filter.patch
ebl update
[bacula/bacula] / bacula / patches / testing / restore_mediatype_storage_filter.patch
1 Index: src/dird/ua.h
2 ===================================================================
3 --- src/dird/ua.h       (revision 8163)
4 +++ src/dird/ua.h       (working copy)
5 @@ -104,6 +104,7 @@
6     JobId_t JobId;
7     char ClientName[MAX_NAME_LENGTH];  /* backup client */
8     char RestoreClientName[MAX_NAME_LENGTH];  /* restore client */
9 +   char MediaType[MAX_NAME_LENGTH];          /* mediatype filter */
10     char last_jobid[20];
11     POOLMEM *JobIds;                   /* User entered string of JobIds */
12     STORE  *store;
13 Index: src/dird/ua_restore.c
14 ===================================================================
15 --- src/dird/ua_restore.c       (revision 8163)
16 +++ src/dird/ua_restore.c       (working copy)
17 @@ -429,21 +429,23 @@
18        "directory",   /* 4 */
19        "select",      /* 5 */
20        "pool",        /* 6 */
21 -      "all",         /* 7 */
22 +      "storage",     /* 7 */
23 +      "mediatype",   /* 8 */
24 +      "all",         /* 9 */
25  
26        /* The keyword below are handled by individual arg lookups */
27 -      "client",       /* 8 */
28 -      "storage",      /* 9 */
29 -      "fileset",      /* 10 */
30 -      "where",        /* 11 */
31 -      "yes",          /* 12 */
32 -      "bootstrap",    /* 13 */
33 -      "done",         /* 14 */
34 -      "strip_prefix", /* 15 */
35 -      "add_prefix",   /* 16 */
36 -      "add_suffix",   /* 17 */
37 -      "regexwhere",   /* 18 */
38 -      "restoreclient", /* 19 */
39 +      "client",       /* 10 */
40 +      "storage",      /* 11 */
41 +      "fileset",      /* 12 */
42 +      "where",        /* 13 */
43 +      "yes",          /* 14 */
44 +      "bootstrap",    /* 15 */
45 +      "done",         /* 16 */
46 +      "strip_prefix", /* 17 */
47 +      "add_prefix",   /* 18 */
48 +      "add_suffix",   /* 19 */
49 +      "regexwhere",   /* 20 */
50 +      "restoreclient", /* 21 */
51        NULL
52     };
53  
54 @@ -531,7 +533,24 @@
55              return 0;
56           }
57           break;
58 -      case 7:                         /* all specified */
59 +      case 7:                   /* storage */
60 +         if (has_value(ua, i)) {
61 +            rx->store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
62 +            if (rx->store && !acl_access_ok(ua,Storage_ACL,rx->store->name())) {
63 +               rx->store = NULL;
64 +            }
65 +         } else {
66 +            rx->store = select_storage_resource(ua);
67 +         }
68 +         break;
69 +      case 8:                   /* mediatype */
70 +         if (has_value(ua, i)) {
71 +            bstrncpy(rx->MediaType, ua->argv[i], sizeof(rx->MediaType));
72 +         } else {
73 +            ua->error_msg(_("Invalid MediaType\n"));
74 +         }
75 +         break;
76 +      case 9:                   /* all specified */
77           rx->all = true;
78           break;
79        /*
80 @@ -1140,7 +1159,8 @@
81     CLIENT_DBR cr;
82     char fileset_name[MAX_NAME_LENGTH];
83     char ed1[50], ed2[50];
84 -   char pool_select[MAX_NAME_LENGTH];
85 +   POOL_MEM other_filter(PM_MESSAGE);
86 +   POOL_MEM temp_filter(PM_MESSAGE);
87     int i;
88  
89     /* Create temp tables */
90 @@ -1196,23 +1216,38 @@
91     }
92  
93     /* If Pool specified, add PoolId specification */
94 -   pool_select[0] = 0;
95     if (rx->pool) {
96 +      Dmsg1(0, "Use %s Pool filter\n",
97 +            rx->pool->name());
98        POOL_DBR pr;
99        memset(&pr, 0, sizeof(pr));
100        bstrncpy(pr.Name, rx->pool->name(), sizeof(pr.Name));
101        if (db_get_pool_record(ua->jcr, ua->db, &pr)) {
102 -         bsnprintf(pool_select, sizeof(pool_select), "AND Media.PoolId=%s ", 
103 -            edit_int64(pr.PoolId, ed1));
104 +         Mmsg(other_filter, "AND Media.PoolId=%s ", 
105 +              edit_int64(pr.PoolId, ed1));
106        } else {
107           ua->warning_msg(_("Pool \"%s\" not found, using any pool.\n"), pr.Name);
108        }
109     }
110 -
111 +   /* use a storage filter */
112 +   if (rx->store) {             /* or use storageid ? */
113 +      Mmsg(temp_filter, " AND Media.StorageId=%s ", 
114 +           edit_int64(rx->store->StorageId, ed1));
115 +      pm_strcat(other_filter, temp_filter.c_str());
116 +      Dmsg2(0, "Use %s StorageId filter (%s)\n",
117 +            rx->store->name(), ed1);
118 +   }
119 +   if (rx->MediaType[0]) {
120 +      Mmsg(temp_filter, " AND Media.MediaType='%s' ", 
121 +           rx->MediaType);
122 +      pm_strcat(other_filter, temp_filter.c_str());
123 +      Dmsg1(0, "Use mediatype filter (%s)\n", rx->MediaType);
124 +   }
125     /* Find JobId of last Full backup for this client, fileset */
126     edit_int64(cr.ClientId, ed1);
127     Mmsg(rx->query, uar_last_full, ed1, ed1, date, fsr.FileSet,
128 -         pool_select);
129 +        other_filter.c_str());
130 +   Dmsg1(0, "q=%s\n", rx->query);
131     if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
132        ua->error_msg("%s\n", db_strerror(ua->db));
133        goto bail_out;
134 @@ -1238,7 +1273,7 @@
135  
136     /* Now find most recent Differental Job after Full save, if any */
137     Mmsg(rx->query, uar_dif, edit_uint64(rx->JobTDate, ed1), date,
138 -        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
139 +        edit_int64(cr.ClientId, ed2), fsr.FileSet, other_filter.c_str());
140     if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
141        ua->warning_msg("%s\n", db_strerror(ua->db));
142     }
143 @@ -1254,7 +1289,7 @@
144  
145     /* Now find all Incremental Jobs after Full/dif save */
146     Mmsg(rx->query, uar_inc, edit_uint64(rx->JobTDate, ed1), date,
147 -        edit_int64(cr.ClientId, ed2), fsr.FileSet, pool_select);
148 +        edit_int64(cr.ClientId, ed2), fsr.FileSet, other_filter.c_str());
149     if (!db_sql_query(ua->db, rx->query, NULL, NULL)) {
150        ua->warning_msg("%s\n", db_strerror(ua->db));
151     }