Skip to content

Instantly share code, notes, and snippets.

@bigbosst
Created October 3, 2014 20:04
Show Gist options
  • Save bigbosst/b8e61b5bc57dffc12f77 to your computer and use it in GitHub Desktop.
Save bigbosst/b8e61b5bc57dffc12f77 to your computer and use it in GitHub Desktop.
Bacula enable/disable individual Server backups, similar to a2ensite a2dissite (yes I know the '2' isn't needed I left it in the names, deal with it)
#!/usr/bin/perl
$file = @ARGV[0];
if($file eq "") {
print "Usage: b2disbackup <server-backup-config>\n";
exit 1;
}
unless(-e "/etc/bacula/backups-enabled/$file") {
print "File already disabled!\n";
exit 2;
}
my $login = (getpwuid $>);
if ($login != 'root') {
print "You must run this script with root privileges!\n";
exit 3;
}
system('rm /etc/bacula/backups-enabled/' . $file);
print "Backup $file disabled.\nTo activate the new configuration, you need to run:\n service bacula-director reload\n";
#!/usr/bin/perl
# Checking for privileges
my $login = (getpwuid $>);
if ($login != 'root') {
print "You must run this script with root privileges!\n";
exit 3;
}
# Checking for vhost file existence
$file = @ARGV[0];
if($file eq "") {
print "Usage: b2enbackup <server-backup-config>\n";
exit 1;
}
unless(-e "/etc/bacula/backups-available/$file") {
print "File doesn't exist!\n";
exit 2;
}
# Checking if already enabled
if(-e "/etc/bacula/backups-enabled/$file") {
print "Backup already enabled. Exiting...\n";
exit 3;
}
# Linking the backup file
system('ln -s "/etc/bacula/backups-available/' . $file . '" "/etc/bacula/backups-enabled/' . $file . '"');
# Checking for errors
my $check = system('service bacula-director configtest 2>/dev/null');
unless($check == 0) {
print "Syntax check failed!\n";
print "Please run 'service bacula-dir configtest' and investigate.\n";
print "Removing the link and exiting...\n";
system('rm /etc/bacula/backups-enabled/' . $file);
exit 4;
}
print "BackupSite $file enabled.\nTo activate the new configuration, you need to run:\n service bacula-director reload\n";
320 @|"sh -c 'cat /etc/bacula/backups-enabled/*.conf'"
# bash completion for Debian apache2 configuration tools
# $Id: apache2,v 1.1 2005/03/16 22:51:19 guillaume Exp $
_bacula_backups()
{
COMPREPLY=( $( compgen -W '$( command ls /etc/bacula/$1 2>/dev/null)' -- $cur ) )
# COMPREPLY=( $( compgen -W '$( command ls /etc/bacula/$1 2>/dev/null \
# | sed -e 's/[.]load$//' -e 's/[.]conf$//' )' -- $cur ) )
}
_b2enbackup()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_bacula_backups backups-available
}
complete -F _b2enbackup b2enbackup
_b2disbackup()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_bacula_backups backups-enabled
}
complete -F _b2disbackup b2disbackup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment