+#
+# Attempt to queue a host.
+# Returns 0 on success; 1 if host is already queued;
+# 2 if host was skipped; 3 on invalid queue name
+#
+# $host is the client's host name
+# $hostIP is usually the client's host name too, or IP address
+# if the user specified it in the manual backup command
+# $user is the user name, or BackupPC by default
+# $queue is which queue to use ("bg" by default)
+# $backupType is the backup type (doIncr|doFull|autoIncr|autoFull|auto|dhcpPoll)
+#
+# Note: starting in 3.2.0, the PC is queued even if it has a current
+# job running
+#
+sub QueueOnePC
+{
+ my($host, $hostIP, $user, $queue, $backupType) = @_;
+ my $retVal = 0;
+ $user = "BackupPC" if ( $user eq '' );
+ $queue = "bg" if ( $queue eq '' && $user eq 'BackupPC' );
+ $backupType = "auto" if ( $backupType eq '' );
+
+ delete($Status{$host}{backoffTime})
+ if ( defined($Status{$host}{backoffTime})
+ && $Status{$host}{backoffTime} < time );
+ return 1 if ( $BgQueueOn{$host} || $UserQueueOn{$host} );
+ if ( $Hosts->{$host}{dhcp} ) {
+ $Status{$host}{dhcpCheckCnt}++;
+ if ( $RunNightlyWhenIdle ) {
+ #
+ # Once per night queue a check for DHCP hosts that just
+ # checks for expired dumps. We need to do this to handle
+ # the case when a DHCP host has not been on the network for
+ # a long time, and some of the old dumps need to be expired.
+ # Normally expiry checks are done by BackupPC_dump only
+ # after the DHCP hosts has been detected on the network.
+ #
+ unshift(@BgQueue,
+ {host => $hostIP, user => $user, reqTime => time,
+ dhcp => 0, dumpExpire => 1});
+ $BgQueueOn{$host} = 1;
+ }
+ } else {
+ #
+ # this is a fixed ip host or DHCP ip address: queue it
+ #
+ if ( $Info{DUlastValue} > $Conf{DfMaxUsagePct} ) {
+ #
+ # Since we are out of disk space, instead of queuing
+ # a regular job, queue an expire check instead. That
+ # way if the admin reduces the number of backups to
+ # keep then we will actually delete them. Otherwise
+ # BackupPC_dump will never run since we have exceeded
+ # the limit.
+ #
+ $retVal = 2;
+ unshift(@BgQueue,
+ {host => $hostIP, user => $user, reqTime => time, dumpExpire => 1});
+ $BgQueueOn{$host} = 1;
+ } elsif( $queue eq 'bg' ) {
+ #
+ # Queue regular background backup
+ #
+ unshift(@BgQueue,
+ {host => $hostIP, user => $user, reqTime => time, backupType => $backupType});
+ $BgQueueOn{$host} = 1;
+ } elsif( $queue eq 'user' ) {
+ #
+ # Queue user backup
+ #
+ unshift(@UserQueue,
+ {host => $hostIP, user => $user, reqTime => time, backupType => $backupType});
+ $UserQueueOn{$host} = 1;
+ } else {
+ # unknown $queue type
+ $retVal = 3;
+ }
+ }
+
+ return $retVal;
+}
+