--- /dev/null
+#! /bin/sh
+# Author : Ludovic Strappazon. l.strappazon@gmail.com
+# Copyright : Kern Sibbald
+# Any comment, advice or enhancement are welcome :-)
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
+MYSQL="/usr/bin/mysql -u bacula --password=cW8s9_aH"
+TMP=/tmp
+BACULA=/usr/local/bacula
+
+PROGNAME=`basename $0`
+PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
+STATUS=""
+
+. $PROGPATH/utils.sh
+
+print_usage() {
+ echo "Usage: $PROGNAME -P <pool> -M <media-type> -w <warning threshold> -c <critical threshold> [-S]"
+}
+
+print_help() {
+ echo ""
+ print_usage
+ echo ""
+ echo "This plugin checks the space available in the pool against the space required for the next scheduled backups"
+ echo "Example : $PROGNAME -P default -M LTO -w 20 -c 10 will check the default pool, return OK if (available space) > 1,20*(required space), WARNING if 1,20*(required space) > (available space) > 1,10*(required space), and CRITICAL else."
+ echo ""
+ echo "With the -S option, it will check the pool named Scratch and return WARNING instead of CRITICAL if the Scratch pool can save the situation."
+ echo "Example : $PROGNAME -P default -M LTO -w 20 -c 10 -S will check the default pool, return OK if (available space) > 1,20*(required space), WARNING if 1,20*(required space) > (available space) > 1,10*(required space) or if (available space in default and Scratch) > 1,10*(required space) > (available space in default), and CRITICAL else."
+ echo ""
+ echo "The evaluation of the space required is done by adding the biggest backups of the same level than the scheduled jobs"
+ echo "The available space is evaluated by the number of out of retention tapes and the average VolBytes of these Full tapes"
+ echo ""
+ echo "The Information Status are : \"Required, Available, Volume Errors\" and \"Will use Scratch pool\" if necessary."
+ echo ""
+ echo "I think this plugin should be used in passive mode, and ran by a RunAfterJob"
+ exit 3
+}
+
+NB_ARGS=$#
+SCRATCH=0
+while getopts :P:M:w:c:hS OPTION
+do
+ case $OPTION in
+ P) POOL="$OPTARG"
+ ;;
+ M) MEDIA_TYPE="$OPTARG"
+ ;;
+ S) SCRATCH=1
+ ;;
+ w) WARNING="$OPTARG"
+ ;;
+ c) CRITICAL="$OPTARG"
+ ;;
+ h) print_help
+ exit 3
+ ;;
+ *) print_usage
+ exit 3
+ ;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [ "$NB_ARGS" -ne 8 -a "$NB_ARGS" -ne 9 ]; then
+ print_revision $PROGNAME 13/06/2006
+ print_usage
+ exit 3
+fi
+
+LAST_CHECK=`ps -ef | grep check_ba[Cc]ula_pools.sh | awk {'print $5'} | uniq | wc -l`
+if [ "$LAST_CHECK" -gt 1 ]; then
+ echo "The last check was not complete, you should increase the check_period."
+ exit 3
+fi
+
+NB_VOLUMES=`$MYSQL << EOF
+USE bacula
+SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND Inchanger = "1";
+EOF`
+
+NB_VOLUMES=`echo $NB_VOLUMES | cut -f 2 -d ' '`
+
+echo "st
+1
+q" | $BACULA/etc/bconsole | sed -n /Scheduled/,/Running/p | grep Backup | tr -s [:blank:] | tr '[:blank:]' '@' > ${TMP}/Scheduled.txt
+
+CAPA_REQUIRED=0
+for LINE in `cat ${TMP}/Scheduled.txt`
+do
+ SCHEDULED_JOB=`echo $LINE | awk -F@ '{print $6}'`
+ LEVEL=`echo $LINE | awk -F@ '{print $1}' | cut -c 1`
+
+MAX_VOLUME_JOB_FOR_LEVEL=`$MYSQL << EOF
+USE bacula
+SELECT MAX(JobBytes) from Job, Pool where Level="$LEVEL" AND Job.Name="$SCHEDULED_JOB" AND Job.PoolId=Pool.PoolId AND Pool.Name="$POOL";
+EOF
+`
+MAX_VOLUME_JOB_FOR_LEVEL=`echo $MAX_VOLUME_JOB_FOR_LEVEL | cut -f 2 -d ' ' `
+
+CAPA_REQUIRED=$[CAPA_REQUIRED+MAX_VOLUME_JOB_FOR_LEVEL]
+done
+
+rm ${TMP}/Scheduled.txt
+
+
+if [ $NB_VOLUMES -gt 0 ]
+then
+
+ NB_VOLUMES_OUT_OF_RETENTION=`$MYSQL << EOF
+USE bacula
+SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND LastWritten <> "0000-00-00 00:00:00" AND UNIX_TIMESTAMP()-UNIX_TIMESTAMP(LastWritten)>Media.VolRetention AND Inchanger = "1";
+EOF
+`
+ NB_VOLUMES_OUT_OF_RETENTION=`echo $NB_VOLUMES_OUT_OF_RETENTION | cut -f 2 -d ' '`
+
+NB_VOLUMES_ERROR=`$MYSQL << EOF
+USE bacula
+SELECT COUNT(MediaId) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND VolStatus="Error" AND Inchanger = "1";
+EOF
+`
+NB_VOLUMES_ERROR=`echo $NB_VOLUMES_ERROR | cut -f 2 -d ' '`
+
+AVERAGE_CAPA_VOLUME=`$MYSQL << EOF
+USE bacula
+SELECT SUM(VolBytes)/COUNT(MediaId) FROM Media where VolStatus="Full" AND MediaType="$MEDIA_TYPE";
+EOF
+`
+AVERAGE_CAPA_VOLUME=`echo $AVERAGE_CAPA_VOLUME | cut -f 2 -d ' ' | cut -f 1 -d '.'`
+
+CAPA_VOLUMES_APPEND=`$MYSQL << EOF
+USE bacula
+SELECT SUM("$AVERAGE_CAPA_VOLUME"-VolBytes) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="$POOL" AND (VolStatus = "Append" OR VolStatus = "Recycle" OR VolStatus = "Purge") AND Inchanger = "1" AND MediaType="$MEDIA_TYPE";
+EOF
+`
+CAPA_VOLUMES_APPEND=`echo $CAPA_VOLUMES_APPEND | cut -f 2 -d ' '`
+
+if [ $SCRATCH -eq 1 ]
+then
+CAPA_VOLUMES_SCRATCH=`$MYSQL << EOF
+USE bacula
+SELECT SUM("$AVERAGE_CAPA_VOLUME"-VolBytes) from Media, Pool where Media.PoolId=Pool.PoolId and Pool.Name="Scratch" AND VolStatus = "Append" AND Inchanger = "1" AND MediaType="$MEDIA_TYPE";
+EOF
+`
+CAPA_VOLUMES_SCRATCH=`echo $CAPA_VOLUMES_SCRATCH | cut -f 2 -d ' '`
+else
+CAPA_VOLUMES_SCRATCH=0
+fi
+
+CAPA_WARNING=`echo $[(WARNING+100)*CAPA_REQUIRED]/100 | bc | cut -f 1 -d '.'`
+CAPA_CRITICAL=`echo $[(CRITICAL+100)*CAPA_REQUIRED]/100 | bc | cut -f 1 -d '.'`
+CAPA_DISP=$[NB_VOLUMES_OUT_OF_RETENTION*AVERAGE_CAPA_VOLUME+CAPA_VOLUMES_APPEND]
+CAPA_DISP_INCLUDING_SCRATCH=$[CAPA_DISP+CAPA_VOLUMES_SCRATCH]
+
+MESSAGE="Required : $[CAPA_REQUIRED/1000000000] Go, available : $[CAPA_DISP/1000000000] Go, Volumes Error : $NB_VOLUMES_ERROR"
+
+if [ "$CAPA_DISP" -gt $CAPA_WARNING ]; then
+ echo $MESSAGE
+ exit 0
+elif [ "$CAPA_DISP" -gt $CAPA_CRITICAL ];then
+ echo $MESSAGE
+ exit 1
+elif [ "$CAPA_DISP_INCLUDING_SCRATCH" -gt $CAPA_CRITICAL ];then
+ MESSAGE="${MESSAGE}. Will use Scratch Pool !"
+ echo $MESSAGE
+ exit 1
+else
+ exit 2
+fi
+exit 3
+
+else
+ echo "No volume in pool ${POOL}"
+ if [ "$CAPA_REQUIRED" -gt 0 ]
+ then exit 2
+ else exit 0
+ fi
+fi
+
Priority:
For 1.39:
+- Remove queue.c code.
- Correct the Include syntax in the m4.xxx files in examples/conf
- Get Perl replacement for bregex.c
- Make base64.c (bin_to_base64) take a buffer length
Kern Sibbald
General:
+08Jul06
+ ======================= Warning ==========================
+ Implemented new method of getting the default Storage from the Media
+ record rather than from the MediaType for restore. As a fall
+ back, if no Storage is defined, use the MediaType. This
+ eliminates most all prompts if there are multiple MediaTypes
+ used. This is an important and fundamental change.
+ ==========================================================
+
+- Add more detail (Storage, Device) to list of volumes printed
+ for restore.
+- More code in migrate. In particular start multiple jobs if
+ migrating a volume.
+- Probably overkill, but ensure that the bsr is unique even within a
+ job in FD and SD.
+- Rework bsys.c drop() so that it now should work as expected.
+- Update a bunch of old copyrights -- particularly in .h files.
+- Remove src/lib/bshm.c/h
05Jul06
- Migration fixes
04Jul06
- Rename the cram_md5 routine names to be slightly more appropriate
to what they are doing (challenge and respond).
- Robert committed his #ifdef and header cleanup.
-
30Jun06
- Fix a complier warning in files/backup.c
- Cleanup NOT NULL vs DEFALT 0 in database creation.
- Write install/uninstall of new manpages. There are now a
pile of man pages. Some of which need a lot of work.
- ============= Warning ==================================
+ ======================= Warning ==========================
The --mandir ./configure option now points to the top level
man directory. The man files will be installed under
mandir/man8 and mandir/man1 as appropriate.
- ===========================================================
+ ==========================================================
- Add complete text of GPL to LICENSE.
- Implement job report that indicates where Storage and Pool
- Detect GCC correctly (I hope)
- If using GCC (actually g++) add the following compiler flags
-fno-strict-aliasing -fno-exceptions -fno-rtti
-- Turn on new bsnprintf() code.
+
+ ===================== Warning =============================
+ Turn on new bsnprintf() code. This could cause print output
+ to look different.
+ ===========================================================
+
- Fix crypto when not using openssl. I previously overlooked this.
- Eliminate crypto type punning problems by eliminating void * and
using uint8_t * instead.
- Harden authentication failure in FD by single threading errors
and forcing a 6 second wait.
- ============= Warning ==================================
+ ===================== Warning =============================
Removed "Accept Any Volume" directive.
===========================================================
* We are called here once for each JobMedia record
* for each Volume.
*/
-static uint32_t write_findex(UAContext *ua, RBSR_FINDEX *fi,
+static uint32_t write_findex(RBSR_FINDEX *fi,
int32_t FirstIndex, int32_t LastIndex, FILE *fd)
{
uint32_t count = 0;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static uint32_t uniq = 0;
-void make_unique_restore_filename(UAContext *ua, POOLMEM **fname)
+static void make_unique_restore_filename(UAContext *ua, POOL_MEM &fname)
{
JCR *jcr = ua->jcr;
int i = find_arg_with_value(ua, "bootstrap");
if (jcr->RestoreBootstrap) {
free(jcr->RestoreBootstrap);
}
- jcr->RestoreBootstrap = bstrdup(*fname);
+ jcr->RestoreBootstrap = bstrdup(fname.c_str());
}
/*
uint32_t write_bsr_file(UAContext *ua, RESTORE_CTX &rx)
{
FILE *fd;
- POOLMEM *fname = get_pool_memory(PM_MESSAGE);
+ POOL_MEM fname(PM_MESSAGE);
+ POOL_MEM volmsg(PM_MESSAGE);
uint32_t count = 0;;
bool err;
char *p;
JobId_t JobId;
+ char Device[MAX_NAME_LENGTH];
- make_unique_restore_filename(ua, &fname);
- fd = fopen(fname, "w+b");
+ make_unique_restore_filename(ua, fname);
+ fd = fopen(fname.c_str(), "w+b");
if (!fd) {
berrno be;
bsendmsg(ua, _("Unable to create bootstrap file %s. ERR=%s\n"),
- fname, be.strerror());
+ fname.c_str(), be.strerror());
goto bail_out;
}
/* Write them to file */
count = write_bsr(ua, rx, fd);
err = ferror(fd);
fclose(fd);
+ if (count == 0) {
+ bsendmsg(ua, _("No files found to restore.\n"));
+ goto bail_out;
+ }
if (err) {
bsendmsg(ua, _("Error writing bsr file.\n"));
count = 0;
}
- bsendmsg(ua, _("Bootstrap records written to %s\n"), fname);
+ bsendmsg(ua, _("Bootstrap records written to %s\n"), fname.c_str());
/* Tell the user what he will need to mount */
bsendmsg(ua, "\n");
- bsendmsg(ua, _("The job will require the following Volumes:\n"));
+ bsendmsg(ua, _("The job will require the following\n"
+ " Volume(s) Storage(s) SD Device(s)\n"
+ "===========================================================================\n"));
/* Create Unique list of Volumes using prompt list */
start_prompt(ua, "");
if (*rx.JobIds) {
}
for (int i=0; i < nbsr->VolCount; i++) {
if (nbsr->VolParams[i].VolumeName[0]) {
- add_prompt(ua, nbsr->VolParams[i].VolumeName);
+ if (!get_storage_device(Device, nbsr->VolParams[i].Storage)) {
+ Device[0] = 0;
+ }
+ Mmsg(volmsg, "%-25.25s %-25.25s %-25.25s",
+ nbsr->VolParams[i].VolumeName,
+ nbsr->VolParams[i].Storage, Device);
+ add_prompt(ua, volmsg.c_str());
}
}
}
for (RBSR *nbsr=rx.bsr; nbsr; nbsr=nbsr->next) {
for (int i=0; i < nbsr->VolCount; i++) {
if (nbsr->VolParams[i].VolumeName[0]) {
- add_prompt(ua, nbsr->VolParams[i].VolumeName);
+ if (!get_storage_device(Device, nbsr->VolParams[i].Storage)) {
+ Device[0] = 0;
+ }
+ Mmsg(volmsg, "%-25.25s %-25.25s %-25.25s",
+ nbsr->VolParams[i].VolumeName,
+ nbsr->VolParams[i].Storage, Device);
+ add_prompt(ua, volmsg.c_str());
}
}
}
bsendmsg(ua, "\n");
bail_out:
- free_pool_memory(fname);
return count;
}
bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */
continue;
}
+ if (!rx.store) {
+ find_storage_resource(ua, rx, bsr->VolParams[i].Storage,
+ bsr->VolParams[i].MediaType);
+ }
fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType);
if (get_storage_device(device, bsr->VolParams[i].Storage)) {
// Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
// bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
- count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
+ count = write_findex(bsr->fi, bsr->VolParams[i].FirstIndex,
bsr->VolParams[i].LastIndex, fd);
if (count) {
fprintf(fd, "Count=%u\n", count);
bsr->VolParams[i].VolumeName[0] = 0; /* zap VolumeName */
continue;
}
+ if (!rx.store) {
+ find_storage_resource(ua, rx, bsr->VolParams[i].Storage,
+ bsr->VolParams[i].MediaType);
+ }
fprintf(fd, "Volume=\"%s\"\n", bsr->VolParams[i].VolumeName);
fprintf(fd, "MediaType=\"%s\"\n", bsr->VolParams[i].MediaType);
if (get_storage_device(device, bsr->VolParams[i].Storage)) {
// Dmsg2(100, "bsr VolParam FI=%u LI=%u\n",
// bsr->VolParams[i].FirstIndex, bsr->VolParams[i].LastIndex);
- count = write_findex(ua, bsr->fi, bsr->VolParams[i].FirstIndex,
+ count = write_findex(bsr->fi, bsr->VolParams[i].FirstIndex,
bsr->VolParams[i].LastIndex, fd);
if (count) {
fprintf(fd, "Count=%u\n", count);
#include <regex.h>
#endif
+static const int dbglevel = 100;
+
static char OKbootstrap[] = "3000 OK bootstrap\n";
static bool get_job_to_migrate(JCR *jcr);
struct idpkt;
return false;
}
- if (!create_restore_bootstrap_file(jcr)) {
- return false;
- }
+ create_restore_bootstrap_file(jcr);
return true;
}
JOB *job, *prev_job;
JCR *prev_jcr; /* newly migrated job */
- if (jcr->previous_jr.JobId == 0) {
+ if (jcr->previous_jr.JobId == 0 || jcr->ExpectedFiles == 0) {
set_jcr_job_status(jcr, JS_Terminated);
migration_cleanup(jcr, jcr->JobStatus);
return true; /* no work */
}
- Dmsg4(000, "Previous: Name=%s JobId=%d Type=%c Level=%c\n",
+ Dmsg4(dbglevel, "Previous: Name=%s JobId=%d Type=%c Level=%c\n",
jcr->previous_jr.Name, jcr->previous_jr.JobId,
jcr->previous_jr.JobType, jcr->previous_jr.JobLevel);
- Dmsg4(000, "Current: Name=%s JobId=%d Type=%c Level=%c\n",
+ Dmsg4(dbglevel, "Current: Name=%s JobId=%d Type=%c Level=%c\n",
jcr->jr.Name, jcr->jr.JobId,
jcr->jr.JobType, jcr->jr.JobLevel);
prev_jcr->jr.FileSetId = jcr->jr.FileSetId;
prev_jcr->jr.JobId = prev_jcr->JobId;
- Dmsg4(000, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
+ Dmsg4(dbglevel, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
prev_jcr->jr.Name, prev_jcr->jr.JobId,
prev_jcr->jr.JobType, prev_jcr->jr.JobLevel);
set_jcr_job_status(jcr, JS_Running);
set_jcr_job_status(prev_jcr, JS_Running);
- Dmsg2(000, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel);
+ Dmsg2(dbglevel, "JobId=%d JobLevel=%c\n", jcr->jr.JobId, jcr->jr.JobLevel);
/* Update job start record for this migration job */
if (!db_update_job_start_record(jcr, jcr->db, &jcr->jr)) {
return false;
}
- Dmsg4(000, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
+ Dmsg4(dbglevel, "Prev_jcr: Name=%s JobId=%d Type=%c Level=%c\n",
prev_jcr->jr.Name, prev_jcr->jr.JobId,
prev_jcr->jr.JobType, prev_jcr->jr.JobLevel);
/*
* Now start a job with the Storage daemon
*/
- Dmsg2(000, "Read store=%s, write store=%s\n",
+ Dmsg2(dbglevel, "Read store=%s, write store=%s\n",
((STORE *)prev_jcr->storage->first())->hdr.name,
((STORE *)jcr->storage->first())->hdr.name);
if (!start_storage_daemon_job(jcr, prev_jcr->storage, jcr->storage)) {
{
idpkt *ids = (idpkt *)ctx;
- Dmsg3(000, "count=%d Ids=%p %s\n", ids->count, ids->list, ids->list);
+ Dmsg3(dbglevel, "count=%d Ids=%p %s\n", ids->count, ids->list, ids->list);
if (ids->count == 0) {
ids->list[0] = 0;
} else {
memset(new_item, 0, sizeof(uitem));
new_item->item = bstrdup(row[0]);
- Dmsg1(000, "Item=%s\n", row[0]);
+ Dmsg1(dbglevel, "Item=%s\n", row[0]);
item = (uitem *)list->binary_insert((void *)new_item, item_compare);
if (item != new_item) { /* already in list */
free(new_item->item);
idpkt ids;
ids.list = get_pool_memory(PM_MESSAGE);
- Dmsg1(000, "list=%p\n", ids.list);
+ Dmsg1(dbglevel, "list=%p\n", ids.list);
ids.list[0] = 0;
ids.count = 0;
if (jcr->MigrateJobId != 0) {
- Dmsg1(000, "previous jobid=%u\n", jcr->MigrateJobId);
+ Dmsg1(000, "At Job start previous jobid=%u\n", jcr->MigrateJobId);
edit_uint64(jcr->MigrateJobId, ids.list);
ids.count = 1;
} else {
}
break;
case MT_CLIENT:
- if (!regex_find_jobids(jcr, &ids, sql_client,
- sql_jobids_from_client, "Client")) {
+ if (!regex_find_jobids(jcr, &ids, sql_client, sql_jobids_from_client, "Client")) {
goto bail_out;
}
break;
case MT_VOLUME:
- if (!regex_find_jobids(jcr, &ids, sql_vol,
- sql_jobids_from_vol, "Volume")) {
+ if (!regex_find_jobids(jcr, &ids, sql_vol, sql_jobids_from_vol, "Volume")) {
goto bail_out;
}
break;
Jmsg(jcr, M_FATAL, 0, _("No Migration SQL selection pattern specified.\n"));
goto bail_out;
}
- Dmsg1(000, "SQL=%s\n", jcr->job->selection_pattern);
+ Dmsg1(dbglevel, "SQL=%s\n", jcr->job->selection_pattern);
if (!db_sql_query(jcr->db, jcr->job->selection_pattern,
dbid_handler, (void *)&ids)) {
Jmsg(jcr, M_FATAL, 0,
}
}
+ /*
+ * Loop over all jobids except the last one, sending
+ * them to start_migration_job(), which will start a job
+ * for each of them. For the last JobId, we handle it below.
+ */
p = ids.list;
+ for (int i=1; i < (int)ids.count; i++) {
+ JobId = 0;
+ stat = get_next_jobid_from_list(&p, &JobId);
+ Dmsg2(000, "get_next_jobid stat=%d JobId=%u\n", stat, JobId);
+ jcr->MigrateJobId = JobId;
+ start_migration_job(jcr);
+ if (stat < 0) {
+ Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
+ goto bail_out;
+ } else if (stat == 0) {
+ Jmsg(jcr, M_INFO, 0, _("No JobIds found to migrate.\n"));
+ goto ok_out;
+ }
+ }
+
+ /* Now get the last JobId and handle it in the current job */
JobId = 0;
stat = get_next_jobid_from_list(&p, &JobId);
- Dmsg2(000, "get_next_jobid stat=%d JobId=%u\n", stat, JobId);
- jcr->MigrateJobId = JobId;
- start_migration_job(jcr);
+ Dmsg2(000, "Last get_next_jobid stat=%d JobId=%u\n", stat, JobId);
if (stat < 0) {
Jmsg(jcr, M_FATAL, 0, _("Invalid JobId found.\n"));
goto bail_out;
Jmsg(jcr, M_INFO, 0, _("No JobIds found to migrate.\n"));
goto ok_out;
}
-
+
jcr->previous_jr.JobId = JobId;
- Dmsg1(000, "Previous jobid=%d\n", jcr->previous_jr.JobId);
+ Dmsg1(100, "Previous jobid=%d\n", jcr->previous_jr.JobId);
if (!db_get_job_record(jcr, jcr->db, &jcr->previous_jr)) {
Jmsg(jcr, M_FATAL, 0, _("Could not get job record for JobId %s to migrate. ERR=%s"),
ua->batch = true;
Mmsg(ua->cmd, "run %s jobid=%s", jcr->job->hdr.name,
edit_uint64(jcr->MigrateJobId, ed1));
- Dmsg1(000, "=============== Migration cmd=%s\n", ua->cmd);
+ Dmsg1(dbglevel, "=============== Migration cmd=%s\n", ua->cmd);
parse_ua_args(ua); /* parse command */
-// int stat = run_cmd(ua, ua->cmd);
- int stat = (int)jcr->MigrateJobId;
+ int stat = run_cmd(ua, ua->cmd);
+// int stat = (int)jcr->MigrateJobId;
if (stat == 0) {
Jmsg(jcr, M_ERROR, 0, _("Could not start migration job.\n"));
} else {
type);
goto bail_out;
}
- Dmsg1(000, "regex=%s\n", jcr->job->selection_pattern);
+ Dmsg1(dbglevel, "regex=%s\n", jcr->job->selection_pattern);
/* Compile regex expression */
rc = regcomp(&preg, jcr->job->selection_pattern, REG_EXTENDED);
if (rc != 0) {
}
/* Basic query for names */
Mmsg(query, query1, jcr->pool->hdr.name);
- Dmsg1(000, "query1=%s\n", query.c_str());
+ Dmsg1(dbglevel, "query1=%s\n", query.c_str());
if (!db_sql_query(jcr->db, query.c_str(), unique_name_handler,
(void *)item_chain)) {
Jmsg(jcr, M_FATAL, 0,
const int nmatch = 30;
regmatch_t pmatch[nmatch];
if (last_item) {
- Dmsg1(000, "Remove item %s\n", last_item->item);
+ Dmsg1(dbglevel, "Remove item %s\n", last_item->item);
free(last_item->item);
item_chain->remove(last_item);
}
- Dmsg1(000, "Jobitem=%s\n", item->item);
+ Dmsg1(dbglevel, "Item=%s\n", item->item);
rc = regexec(&preg, item->item, nmatch, pmatch, 0);
if (rc == 0) {
last_item = NULL; /* keep this one */
}
if (last_item) {
free(last_item->item);
- Dmsg1(000, "Remove item %s\n", last_item->item);
+ Dmsg1(dbglevel, "Remove item %s\n", last_item->item);
item_chain->remove(last_item);
}
regfree(&preg);
*/
ids->count = 0;
foreach_dlist(item, item_chain) {
- Dmsg1(000, "Got Job: %s\n", item->item);
+ Dmsg2(dbglevel, "Got %s: %s\n", type, item->item);
Mmsg(query, query2, item->item, jcr->pool->hdr.name);
- Dmsg1(000, "query2=%s\n", query.c_str());
+ Dmsg1(dbglevel, "query2=%s\n", query.c_str());
if (!db_sql_query(jcr->db, query.c_str(), dbid_handler, (void *)ids)) {
Jmsg(jcr, M_FATAL, 0,
_("SQL failed. ERR=%s\n"), db_strerror(jcr->db));
}
ok = true;
bail_out:
- Dmsg2(000, "Count=%d Jobids=%s\n", ids->count, ids->list);
+ Dmsg2(dbglevel, "Count=%d Jobids=%s\n", ids->count, ids->list);
delete item_chain;
- Dmsg0(000, "After delete item_chain\n");
+ Dmsg0(dbglevel, "After delete item_chain\n");
return ok;
}
/* ua_restore.c */
int get_next_jobid_from_list(char **p, JobId_t *JobId);
+void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType);
/* ua_server.c */
void bsendmsg(void *sock, const char *fmt, ...);
static int jobid_handler(void *ctx, int num_fields, char **row);
static int user_select_jobids_or_files(UAContext *ua, RESTORE_CTX *rx);
static int fileset_handler(void *ctx, int num_fields, char **row);
-static void print_name_list(UAContext *ua, NAME_LIST *name_list);
-static int unique_name_list_handler(void *ctx, int num_fields, char **row);
static void free_name_list(NAME_LIST *name_list);
-static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx);
static bool select_backups_before_date(UAContext *ua, RESTORE_CTX *rx, char *date);
static bool build_directory_tree(UAContext *ua, RESTORE_CTX *rx);
static void free_rx(RESTORE_CTX *rx);
}
pm_strcpy(ua->cmd, ua->argv[i]);
insert_one_file_or_dir(ua, rx, date, j==4);
- if (rx->name_list.num_ids) {
- /* Check MediaType and select storage that corresponds */
- get_storage_from_mediatype(ua, &rx->name_list, rx);
- done = true;
- }
- break;
+ return 2;
case 5: /* select */
if (!have_date) {
bstrutime(date, sizeof(date), time(NULL));
break;
}
}
- if (rx->name_list.num_ids) {
- return 2; /* filename list made */
- }
if (!done) {
bsendmsg(ua, _("\nFirst you select one or more JobIds that contain files\n"
}
insert_one_file_or_dir(ua, rx, date, false);
}
- /* Check MediaType and select storage that corresponds */
- if (rx->name_list.num_ids) {
- get_storage_from_mediatype(ua, &rx->name_list, rx);
- }
return 2;
case 7: /* enter files backed up before specified time */
if (!get_date(ua, date, sizeof(date))) {
}
insert_one_file_or_dir(ua, rx, date, false);
}
- /* Check MediaType and select storage that corresponds */
- if (rx->name_list.num_ids) {
- get_storage_from_mediatype(ua, &rx->name_list, rx);
- }
return 2;
case 8: /* Find JobIds for current backup */
}
insert_one_file_or_dir(ua, rx, date, true);
}
- /* Check MediaType and select storage that corresponds */
- if (rx->name_list.num_ids) {
- get_storage_from_mediatype(ua, &rx->name_list, rx);
- }
return 2;
case 11: /* Cancel or quit */
static bool insert_file_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *file,
char *date)
{
- char ed1[50];
-
strip_trailing_newline(file);
split_path_and_filename(rx, file);
if (*rx->JobIds == 0) {
bsendmsg(ua, _("No database record found for: %s\n"), file);
return true;
}
- /*
- * Find the MediaTypes for this JobId and add to the name_list
- */
- Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1));
- if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- return false;
- }
return true;
}
static bool insert_dir_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *dir,
char *date)
{
- char ed1[50];
-
strip_trailing_junk(dir);
if (*rx->JobIds == 0) {
bsendmsg(ua, _("No JobId specified cannot continue.\n"));
bsendmsg(ua, _("No database record found for: %s\n"), dir);
return true;
}
- /*
- * Find the MediaTypes for this JobId and add to the name_list
- */
- Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1));
- if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- return false;
- }
return true;
}
*/
static bool insert_table_into_findex_list(UAContext *ua, RESTORE_CTX *rx, char *table)
{
- char ed1[50];
-
strip_trailing_junk(table);
Mmsg(rx->query, uar_jobid_fileindex_from_table, table);
bsendmsg(ua, _("No table found: %s\n"), table);
return true;
}
- /*
- * Find the MediaTypes for this JobId and add to the name_list
- */
- Mmsg(rx->query, uar_mediatype, edit_int64(rx->JobId, ed1));
- if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- return false;
- }
return true;
}
if (!db_sql_query(ua->db, rx->query, insert_tree_handler, (void *)&tree)) {
bsendmsg(ua, "%s", db_strerror(ua->db));
}
- /*
- * Find the MediaTypes for this JobId and add to the name_list
- */
- Mmsg(rx->query, uar_mediatype, edit_int64(JobId, ed1));
- if (!db_sql_query(ua->db, rx->query, unique_name_list_handler, (void *)&rx->name_list)) {
- bsendmsg(ua, "%s", db_strerror(ua->db));
- }
}
if (tree.FileCount == 0) {
bsendmsg(ua, _("\nThere were no files inserted into the tree, so file selection\n"
}
}
- /* Check MediaType and select storage that corresponds */
- get_storage_from_mediatype(ua, &rx->name_list, rx);
-
if (find_arg(ua, NT_("done")) < 0) {
/* Let the user interact in selecting which files to restore */
OK = user_select_files_from_tree(&tree);
return 0;
}
+#ifdef xxxx_needed
/*
* Called here with each name to be added to the list. The name is
* added to the list if it is not already in the list.
*
- * Used to make unique list of FileSets and MediaTypes
+ * Used to make unique list of FileSets
*/
static int unique_name_list_handler(void *ctx, int num_fields, char **row)
{
bsendmsg(ua, "%s\n", name_list->name[i]);
}
}
+#endif
/*
name_list->num_ids = 0;
}
+void find_storage_resource(UAContext *ua, RESTORE_CTX &rx, char *Storage, char *MediaType)
+{
+ STORE *store;
+
+ if (rx.store) {
+ return;
+ }
+ /*
+ * Try looking up Storage by name
+ */
+ LockRes();
+ foreach_res(store, R_STORAGE) {
+ if (strcmp(Storage, store->hdr.name) == 0) {
+ if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+ rx.store = store;
+ }
+ break;
+ }
+ }
+ UnlockRes();
+
+ if (rx.store) {
+ /* Check if an explicit storage resource is given */
+ store = NULL;
+ int i = find_arg_with_value(ua, "storage");
+ if (i > 0) {
+ store = (STORE *)GetResWithName(R_STORAGE, ua->argv[i]);
+ if (store && !acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+ store = NULL;
+ }
+ }
+ if (store && (store != rx.store)) {
+ bsendmsg(ua, _("Warning default storage overridden by \"%s\" on command line.\n"),
+ store->hdr.name);
+ rx.store = store;
+ }
+ return;
+ }
+
+ /* If no storage resource, try to find one from MediaType */
+ if (!rx.store) {
+ LockRes();
+ foreach_res(store, R_STORAGE) {
+ if (strcmp(MediaType, store->media_type) == 0) {
+ if (acl_access_ok(ua, Storage_ACL, store->hdr.name)) {
+ rx.store = store;
+ bsendmsg(ua, _("Storage \"%s\" not found, using Storage \"%s\" from MediaType \"%s\".\n"),
+ Storage, store->hdr.name, MediaType);
+ }
+ UnlockRes();
+ return;
+ }
+ }
+ UnlockRes();
+ bsendmsg(ua, _("\nUnable to find Storage resource for\n"
+ "MediaType \"%s\", needed by the Jobs you selected.\n"), MediaType);
+ }
+
+ /* Take command line arg, or ask user if none */
+ rx.store = get_storage_resource(ua, false /* don't use default */);
+
+}
+
+
+#ifdef xxxx_needed
static void get_storage_from_mediatype(UAContext *ua, NAME_LIST *name_list, RESTORE_CTX *rx)
{
STORE *store;
if (name_list->num_ids > 1) {
bsendmsg(ua, _("Warning, the JobIds that you selected refer to more than one MediaType.\n"
- "Restore is not possible. The MediaTypes used are:\n"));
+ "Restore may not be possible. The MediaTypes used are:\n"));
print_name_list(ua, name_list);
- rx->store = select_storage_resource(ua);
+// rx->store = select_storage_resource(ua);
return;
}
name_list->name[0]);
}
}
+#endif
}
+static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER;
+static uint32_t bsr_uniq = 0;
+
/*
* The Director sends us the bootstrap file, which
* we will in turn pass to the SD.
FILE *bs;
free_bootstrap(jcr);
- Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
- jcr->Job);
+ P(bsr_mutex);
+ bsr_uniq++;
+ Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name,
+ jcr->Job, bsr_uniq);
+ V(bsr_mutex);
Dmsg1(400, "bootstrap=%s\n", fname);
jcr->RestoreBootstrap = fname;
bs = fopen(fname, "a+b"); /* create file */
+bsnprintf
save
1
Makefile
LIBSRCS = alloc.c attr.c base64.c berrno.c bsys.c bget_msg.c \
bnet.c bnet_server.c runscript.c \
- bpipe.c bshm.c bsnprintf.c btime.c \
+ bpipe.c bsnprintf.c btime.c \
cram-md5.c crc32.c crypto.c daemon.c edit.c fnmatch.c \
hmac.c idcache.c jcr.c lex.c alist.c dlist.c \
md5.c message.c mem_pool.c openssl.c parse_conf.c \
LIBOBJS = alloc.o attr.o base64.o berrno.o bsys.o bget_msg.o \
bnet.o bnet_server.o runscript.o \
- bpipe.o bshm.o bsnprintf.o btime.o \
+ bpipe.o bsnprintf.o btime.o \
cram-md5.o crc32.o crypto.o daemon.o edit.o fnmatch.o \
hmac.o idcache.o jcr.o lex.o alist.o dlist.o \
md5.o message.o mem_pool.o openssl.o parse_conf.o \
/*
*
- * Written by Meno Abels, June MMIIII
+ * Written by Meno Abels, June MMIV
*
* Version $Id$
*/
-
/*
- Copyright (C) 2004-2005 Kern Sibbald
+ Copyright (C) 2004-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
-
class IPADDR : public SMARTALLOC {
public:
typedef enum { R_SINGLE, R_SINGLE_PORT, R_SINGLE_ADDR, R_MULTIPLE,
*
* Version $Id$
*/
-
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2003-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
+
struct ATTR {
int32_t stream; /* attribute stream id */
int32_t data_stream; /* id of data stream to follow */
+++ /dev/null
-/*
- * Bacula shared memory routines
- *
- * To avoid problems with several return arguments, we
- * pass a packet.
- *
- * BSHM definition is in bshm.h
- *
- * By Kern Sibbald, May MM
- *
- * Version $Id$
- *
- * Note, this routine was originally written so that the DEVICE structures
- * could be shared between the child processes. Now that the Storage
- * daemon is threaded, these routines are no longer needed. Rather than
- * rewrite all the code, I simply #ifdef it on NEED_SHARED_MEMORY, and
- * when not defined, I simply malloc() a buffer, which is, of course,
- * available to all the threads.
- *
- */
-/*
- Copyright (C) 2000-2006 Kern Sibbald
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as amended with additional clauses defined in the
- file LICENSE in the main source directory.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
-
- */
-
-
-#ifdef implemented
-
-#include "bacula.h"
-
-#if !defined(HAVE_WIN32)
-
-#ifdef NEED_SHARED_MEMORY
-#define SHM_KEY 0x0BACB01 /* key for shared memory */
-static key_t shmkey = SHM_KEY;
-#define MAX_TRIES 1000
-
-#else /* threaded model */
-/* Multiple thread protection */
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-
-/* Create shared memory segment defined by BSHM */
-void shm_create(BSHM *shm)
-{
-#ifdef NEED_SHARED_MEMORY
- int shmid, i;
- int not_found = TRUE;
-
- Dmsg1(110, "shm_create size=%d\n", shm->size);
- for (i=0; i<MAX_TRIES; i++) {
- if ((shmid = shmget(shmkey, shm->size, shm->perms | IPC_CREAT)) < 0) {
- Emsg1(M_WARN, 0, _("shmget failure key = %x\n"), shmkey);
- shmkey++;
- continue;
- }
- not_found = FALSE;
- break;
- }
- if (not_found)
- Emsg2(M_ABORT, 0, _("Could not get %d bytes of shared memory: %s\n"), shm->size, strerror(errno));
- shm->shmkey = shmkey;
- shm->shmid = shmid;
- Dmsg2(110, "shm_create return key=%x id=%d\n", shmkey, shmid);
- shmkey++; /* leave set for next time */
-#else
- shm->shmbuf = NULL;
- shm->shmkey = 0; /* reference count */
-#endif
-}
-
-/* Attach to shared memory segement defined in BSHM */
-void *shm_open(BSHM *shm)
-{
-#ifdef NEED_SHARED_MEMORY
- int shmid;
- char *shmbuf;
-
- Dmsg2(110, "shm_open key=%x size=%d\n", shm->shmkey, shm->size);
- if ((shmid = shmget(shm->shmkey, shm->size, 0)) < 0)
- Emsg2(M_ABORT, 0, "Could not get %d bytes of shared memory: %s\n", shm->size, strerror(errno));
- Dmsg1(110, "shm_open shmat with id=%d\n", shmid);
- shmbuf = shmat(shmid, NULL, 0);
- Dmsg1(110, "shm_open buf=%x\n", shmbuf);
- if (shmbuf == (char *) -1)
- Emsg1(M_ABORT, 0, _("Could not attach shared memory: %s\n"), strerror(errno));
- shm->shmbuf = shmbuf;
- shm->shmid = shmid;
- return shmbuf;
-#else
- P(mutex);
- if (!shm->shmbuf) {
- shm->shmbuf = bmalloc(shm->size);
- }
- shm->shmkey++; /* reference count */
- V(mutex);
- return shm->shmbuf;
-#endif
-}
-
-/* Detach from shared memory segement */
-void shm_close(BSHM *shm)
-{
-#ifdef NEED_SHARED_MEMORY
- if (shm->size) {
- if (shmdt(shm->shmbuf) < 0) {
- Emsg1(M_ERROR, 0, _("Error detaching shared memory: %s\n"), strerror(errno));
- }
- }
-#else
- P(mutex);
- shm->shmkey--; /* reference count */
- V(mutex);
-#endif
-}
-
-/* Destroy the shared memory segment */
-void shm_destroy(BSHM *shm)
-{
-#ifdef NEED_SHARED_MEMORY
- if (shm->size) {
- if (shmctl(shm->shmid, IPC_RMID, NULL) < 0) {
- Emsg1(M_ERROR, 0, _("Could not destroy shared memory: %s\n"), strerror(errno));
- }
- }
-#else
- /* We really should check that the ref count is zero */
- P(mutex);
- if (shm->shmbuf) {
- free(shm->shmbuf);
- shm->shmbuf = NULL;
- }
- V(mutex);
-#endif
-}
-
-#endif /* ! HAVE_WIN32 */
-
-#endif
+++ /dev/null
-/*
- * Bacula Shared Memory structure
- *
- * Kern Sibbald, May MM
- *
- * NB: these items are deprecated. Shared memory was
- * used in a first version of the Storage daemon
- * when it forked. Since then it has been converted
- * to use threads. However, there are still some
- * vestiges of the shared memory code that remain and
- * can be removed.
- *
- * Version $Id$
- */
-/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
-
- */
-
-typedef struct s_bshm {
- int size; /* length desired */
- int perms; /* permissions desired */
-
- int shmid; /* id set by shm_create and shm_open */
- key_t shmkey; /* key set by shm_create */
- void *shmbuf; /* set by shm_open */
-} BSHM;
/*
* Drop to privilege new userid and new gid if non-NULL
*/
-void drop(char *uid, char *gid)
+void drop(char *uname, char *gname)
{
-#ifdef HAVE_GRP_H
- if (gid) {
- struct group *group;
- gid_t gr_list[1];
+#if defined(HAVE_PWD_H) && defined(HAVE_GRP_H)
+ struct passwd *passw = NULL;
+ struct group *group = NULL;
+ gid_t gid;
+
+ Dmsg2(900, "uname=%s gname=%s\n", uname?uname:"NONE", gname?gname:"NONE");
+ if (!uname && !gname) {
+ return; /* Nothing to do */
+ }
- if ((group = getgrnam(gid)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, _("Could not find specified group: %s\n"), gid);
+ if (uname) {
+ if ((passw = getpwnam(uname)) == NULL) {
+ berrno be;
+ Emsg2(M_ERROR_TERM, 0, _("Could not find userid=%s: ERR=%s\n"), uname,
+ be.strerror());
}
- if (setgid(group->gr_gid)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
+ } else {
+ if ((passw = getpwuid(getuid())) == NULL) {
+ berrno be;
+ Emsg1(M_ERROR_TERM, 0, _("Could not find password entry. ERR=%s\n"),
+ be.strerror());
+ } else {
+ uname = passw->pw_name;
}
- gr_list[0] = group->gr_gid;
- if (setgroups(1, gr_list)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified group: %s\n"), gid);
+ }
+ if (gname) {
+ if ((group = getgrnam(gname)) == NULL) {
+ berrno be;
+ Emsg2(M_ERROR_TERM, 0, _("Could not find group=%s: ERR=%s\n"), gname,
+ be.strerror());
}
+ gid = group->gr_gid;
+ } else {
+ gid = passw->pw_gid;
}
-#endif
-
-#ifdef HAVE_PWD_H
- if (uid) {
- struct passwd *passw;
- if ((passw = getpwnam(uid)) == NULL) {
- Emsg1(M_ERROR_TERM, 0, _("Could not find specified userid: %s\n"), uid);
+ if (initgroups(passw->pw_name, passw->pw_gid)) {
+ berrno be;
+ if (gname) {
+ Emsg3(M_ERROR_TERM, 0, _("Could not initgroups for group=%s, userid=%s: ERR=%s\n"),
+ gname, uname, be.strerror());
+ } else {
+ Emsg2(M_ERROR_TERM, 0, _("Could not initgroups for userid=%s: ERR=%s\n"),
+ uname, be.strerror());
}
- if (setuid(passw->pw_uid)) {
- Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uid);
+ }
+ if (gname) {
+ if (setgid(group->gr_gid)) {
+ berrno be;
+ Emsg2(M_ERROR_TERM, 0, _("Could not set group=%s: ERR=%s\n"), gname,
+ be.strerror());
}
}
+ if (setuid(passw->pw_uid)) {
+ berrno be;
+ Emsg1(M_ERROR_TERM, 0, _("Could not set specified userid: %s\n"), uname);
+ }
#endif
-
}
Version $Id$
*/
-
/*
- Copyright (C) 2000-2004 Kern Sibbald and John Walker
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
/* =========================================================== */
-/* old code deprecated below. Do not use. */
+/* old code deprecated below. Do not use. */
-typedef float64_t fdate_t; /* Date type */
-typedef float64_t ftime_t; /* Time type */
+typedef float64_t fdate_t; /* Date type */
+typedef float64_t ftime_t; /* Time type */
struct date_time {
- fdate_t julian_day_number; /* Julian day number */
+ fdate_t julian_day_number; /* Julian day number */
ftime_t julian_day_fraction; /* Julian day fraction */
};
/* In arguments and results of the following functions,
quantities are expressed as follows.
- year Year in the Common Era. The canonical
- date of adoption of the Gregorian calendar
- (October 5, 1582 in the Julian calendar)
- is assumed.
+ year Year in the Common Era. The canonical
+ date of adoption of the Gregorian calendar
+ (October 5, 1582 in the Julian calendar)
+ is assumed.
- month Month index with January 0, December 11.
+ month Month index with January 0, December 11.
- day Day number of month, 1 to 31.
+ day Day number of month, 1 to 31.
*/
extern fdate_t date_encode(uint32_t year, uint8_t month, uint8_t day);
extern ftime_t time_encode(uint8_t hour, uint8_t minute, uint8_t second,
- float32_t second_fraction);
+ float32_t second_fraction);
extern void date_time_encode(struct date_time *dt,
- uint32_t year, uint8_t month, uint8_t day,
- uint8_t hour, uint8_t minute, uint8_t second,
- float32_t second_fraction);
+ uint32_t year, uint8_t month, uint8_t day,
+ uint8_t hour, uint8_t minute, uint8_t second,
+ float32_t second_fraction);
extern void date_decode(fdate_t date, uint32_t *year, uint8_t *month,
- uint8_t *day);
+ uint8_t *day);
extern void time_decode(ftime_t time, uint8_t *hour, uint8_t *minute,
- uint8_t *second, float32_t *second_fraction);
+ uint8_t *second, float32_t *second_fraction);
extern void date_time_decode(struct date_time *dt,
- uint32_t *year, uint8_t *month, uint8_t *day,
- uint8_t *hour, uint8_t *minute, uint8_t *second,
- float32_t *second_fraction);
+ uint32_t *year, uint8_t *month, uint8_t *day,
+ uint8_t *hour, uint8_t *minute, uint8_t *second,
+ float32_t *second_fraction);
extern int date_time_compare(struct date_time *dt1, struct date_time *dt2);
* Version $Id$
*/
/*
- Copyright (C) 2005 Kern Sibbald
+ Copyright (C) 2005-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
#include "parse_conf.h"
#include "tls.h"
#include "bsock.h"
-#include "bshm.h"
#include "workq.h"
#ifndef HAVE_FNMATCH
#include "fnmatch.h"
* Version $Id$
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2001-2006 Kern Sibbald
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
- This library is distributed in the hope that it will be useful,
+ This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
* Version $Id$
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
} DEST;
/* Message Destination values for dest field of DEST */
-#define MD_SYSLOG 1 /* send msg to syslog */
-#define MD_MAIL 2 /* email group of messages */
-#define MD_FILE 3 /* write messages to a file */
-#define MD_APPEND 4 /* append messages to a file */
-#define MD_STDOUT 5 /* print messages */
-#define MD_STDERR 6 /* print messages to stderr */
-#define MD_DIRECTOR 7 /* send message to the Director */
-#define MD_OPERATOR 8 /* email a single message to the operator */
-#define MD_CONSOLE 9 /* send msg to UserAgent or console */
-#define MD_MAIL_ON_ERROR 10 /* email messages if job errors */
+enum {
+ MD_SYSLOG = 1, /* send msg to syslog */
+ MD_MAIL, /* email group of messages */
+ MD_FILE, /* write messages to a file */
+ MD_APPEND, /* append messages to a file */
+ MD_STDOUT, /* print messages */
+ MD_STDERR, /* print messages to stderr */
+ MD_DIRECTOR, /* send message to the Director */
+ MD_OPERATOR, /* email a single message to the operator */
+ MD_CONSOLE, /* send msg to UserAgent or console */
+ MD_MAIL_ON_ERROR /* email messages if job errors */
+};
/* Queued message item */
struct MQUEUE_ITEM {
* license please contact Landon Fuller <landonf@opendarwin.org>.
*/
/*
- Copyright (C) 2005 Kern Sibbald
+ Copyright (C) 2005-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
/*
* Version $Id$
*/
-
-
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
-
/* General purpose queue */
struct b_queue {
- struct b_queue *qnext, /* Next item in queue */
- *qprev; /* Previous item in queue */
+ struct b_queue *qnext, /* Next item in queue */
+ *qprev; /* Previous item in queue */
};
typedef struct b_queue BQUEUE;
/* Queue functions */
-void qinsert(BQUEUE *qhead, BQUEUE *object);
+void qinsert(BQUEUE *qhead, BQUEUE *object);
BQUEUE *qnext(BQUEUE *qhead, BQUEUE *qitem);
BQUEUE *qdchain(BQUEUE *qitem);
BQUEUE *qremove(BQUEUE *qhead);
* Version $Id$
*/
/*
- Copyright (C) 2000-2006 Kern Sibbald
+ Copyright (C) 2006-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
* Version $Id$
*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
*
* Version $Id$
*/
-
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
+
/* Serialisation support functions from serial.c. */
extern void serial_int16(uint8_t * * const ptr, const int16_t v);
/*
- Serialisation Macros
+ Serialisation Macros
These macros use a uint8_t pointer, ser_ptr, which must be
defined by the code which uses them.
#define unser_begin(x, s) ser_ptr = ((uint8_t *)(x))
/* ser_length -- Determine length in bytes of serialised into a
- buffer x. */
+ buffer x. */
#define ser_length(x) (ser_ptr - (uint8_t *)(x))
#define unser_length(x) (ser_ptr - (uint8_t *)(x))
#define unser_end(x, s) ASSERT(ser_length(x) <= (s))
/* ser_check(x, s) -- Verify length of serialised data in buffer x is
- expected length s. */
+ expected length s. */
#define ser_check(x, s) ASSERT(ser_length(x) == (s))
/* Serialisation */
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
* Modified for use with Bacula by Kern Sibbald, June 2003
*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2003-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
*
*/
/*
- Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+ Copyright (C) 2001-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
*/
typedef struct waitq_ele_tag {
struct waitq_ele_tag *next;
- int done_flag; /* predicate for wait */
- pthread_cont_t done; /* wait for completion */
- void *msg; /* message to be passed */
+ int done_flag; /* predicate for wait */
+ pthread_cont_t done; /* wait for completion */
+ void *msg; /* message to be passed */
} waitq_ele_t;
/*
* Structure describing a wait queue
*/
typedef struct workq_tag {
- pthread_mutex_t mutex; /* queue access control */
- pthread_cond_t wait_req; /* wait for OK */
- int num_msgs; /* number of waiters */
- waitq_ele_t *first; /* wait queue first item */
- waitq_ele_t *last; /* wait queue last item */
+ pthread_mutex_t mutex; /* queue access control */
+ pthread_cond_t wait_req; /* wait for OK */
+ int num_msgs; /* number of waiters */
+ waitq_ele_t *first; /* wait queue first item */
+ waitq_ele_t *last; /* wait queue last item */
} workq_t;
extern int waitq_init(waitq_t *wq);
*
*/
/*
- Copyright (C) 2002-2004 Kern Sibbald and John Walker
+ Copyright (C) 2002-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
#define TIMEOUT_SIGNAL SIGUSR2
struct s_watchdog_t {
- bool one_shot;
- time_t interval;
- void (*callback)(struct s_watchdog_t *wd);
- void (*destructor)(struct s_watchdog_t *wd);
- void *data;
- /* Private data below - don't touch outside of watchdog.c */
- dlink link;
- time_t next_fire;
+ bool one_shot;
+ time_t interval;
+ void (*callback)(struct s_watchdog_t *wd);
+ void (*destructor)(struct s_watchdog_t *wd);
+ void *data;
+ /* Private data below - don't touch outside of watchdog.c */
+ dlink link;
+ time_t next_fire;
};
typedef struct s_watchdog_t watchdog_t;
* Version $Id$
*/
/*
- Copyright (C) 2000-2003 Kern Sibbald and John Walker
+ Copyright (C) 2001-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
#define WORKQ_VALID 0xdec1992
extern int workq_init(
- workq_t *wq,
- int threads, /* maximum threads */
- void *(*engine)(void *) /* engine routine */
- );
+ workq_t *wq,
+ int threads, /* maximum threads */
+ void *(*engine)(void *) /* engine routine */
+ );
extern int workq_destroy(workq_t *wq);
extern int workq_add(workq_t *wq, void *element, workq_ele_t **work_item, int priority);
extern int workq_remove(workq_t *wq, workq_ele_t *work_item);
return get_bootstrap_file(jcr, jcr->file_bsock);
}
+static pthread_mutex_t bsr_mutex = PTHREAD_MUTEX_INITIALIZER;
+static uint32_t bsr_uniq = 0;
+
bool get_bootstrap_file(JCR *jcr, BSOCK *sock)
{
POOLMEM *fname = get_pool_memory(PM_FNAME);
unlink(jcr->RestoreBootstrap);
free_pool_memory(jcr->RestoreBootstrap);
}
- Mmsg(fname, "%s/%s.%s.bootstrap", me->working_directory, me->hdr.name,
- jcr->Job);
+ P(bsr_mutex);
+ bsr_uniq++;
+ Mmsg(fname, "%s/%s.%s.%d.bootstrap", me->working_directory, me->hdr.name,
+ jcr->Job, bsr_uniq);
+ V(bsr_mutex);
Dmsg1(400, "bootstrap=%s\n", fname);
jcr->RestoreBootstrap = fname;
bs = fopen(fname, "a+b"); /* create file */
goto bail_out;
}
- Dmsg3(000, "Found %d volumes names for %s. First=%s\n", jcr->NumVolumes,
+ Dmsg3(200, "Found %d volumes names for %s. First=%s\n", jcr->NumVolumes,
jcr->VolList->VolumeName, Type);
/* Ready devices for reading and writing */
*/
#undef VERSION
-#define VERSION "1.39.15"
-#define BDATE "5 July 2006"
-#define LSMDATE "05Jul06"
+#define VERSION "1.39.16"
+#define BDATE "8 July 2006"
+#define LSMDATE "08Jul06"
/* Debug flags */
#undef DEBUG