]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
truncate volumes from a script
authorPeter Palfrader <peter@palfrader.org>
Sun, 24 Mar 2013 22:55:13 +0000 (23:55 +0100)
committerPeter Palfrader <peter@palfrader.org>
Sun, 24 Mar 2013 22:55:13 +0000 (23:55 +0100)
modules/bacula/files/bacula-volume-purge-action [new file with mode: 0755]
modules/bacula/manifests/director.pp
modules/bacula/manifests/node.pp
modules/bacula/templates/bacula-dir.conf.erb
modules/bacula/templates/per-client.conf.erb

diff --git a/modules/bacula/files/bacula-volume-purge-action b/modules/bacula/files/bacula-volume-purge-action
new file mode 100755 (executable)
index 0000000..03c0822
--- /dev/null
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+# sends purge volume action=all to bacula using bconsole.
+# list of storages is read from stdin
+
+# Copyright 2013 Peter Palfrader
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+import optparse
+import subprocess
+import sys
+
+
+parser = optparse.OptionParser()
+parser.set_usage("%prog [options]")
+parser.add_option("-v", "--verbose", dest="verbose",
+  default=False, action="store_true",
+  help="Be more verbose.")
+(options, args) = parser.parse_args()
+
+if len(args) >= 1:
+    parser.print_help()
+    sys.exit(1)
+
+cmd = []
+for storage in sys.stdin:
+    s = storage.rstrip()
+    c = 'purge volume action=all allpools storage=%s'%(s,)
+    cmd.append(c)
+if options.verbose:
+    for c in cmd:
+      print "Will run: %s"%(c,)
+
+p = subprocess.Popen(['bconsole'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+(out, err) = p.communicate("\n".join(cmd))
+if p.returncode != 0:
+    raise Exception("bconsole failed.  stdout:\n%s\nstderr:%s\n"%(out, err))
+
+if options.verbose:
+    print "stdout:\n%s"%(out,)
+
+if err != "":
+  print >> sys.stderr, "bconsole said on stderr:\n%s\n"%(err,)
+  sys.exit(1)
index 0afd927f1cc4bb1a08ff1fedc733a7483911b606..818cfd6f0a7f3eb5103a0b831f1f7311c9d59252 100644 (file)
@@ -62,4 +62,22 @@ class bacula::director inherits bacula {
                group   => bacula,
                require => Package['bacula-console']
        }
+
+       file { '/etc/bacula/bacula-volume-purge-action':
+               mode    => '0555',
+               source  => 'puppet:///modules/bacula/bacula-volume-purge-action',
+               ;
+       }
+       file { '/etc/bacula/storages-list.d':
+               ensure  => directory,
+               mode    => '0755',
+               group   => bacula,
+               purge   => true,
+               force   => true,
+               recurse => true,
+               source  => 'puppet:///files/empty/',
+       }
+       file { "/etc/cron.d/tor-bacula-stuff":
+               content => "@daily root (cat /etc/bacula/storages-list.d/*.storage; echo '$bacula::bacula_filestor_name-catalog') | /etc/bacula/bacula-volume-purge-action\n";
+       }
 }
index 5552627ae90d0ec9c97932efde8094e22ddcad94..f105d5c063877e38bfb7a3cc136763252e8f7ca8 100644 (file)
@@ -24,5 +24,12 @@ define bacula::node() {
                group   => bacula,
                notify  => Exec['bacula-director reload']
        }
+
+       file { "/etc/bacula/storages-list.d/${name}.storage":
+               content => "$bacula::bacula_filestor_device-$client\n",
+               mode    => '0440',
+               group   => bacula,
+               notify  => Exec['bacula-director reload']
+       }
 }
 
index 9132a553f32068e54f5a95590b29dc2ea8a38692..3ceb660bfa13803ec843c2e3e8d4910bccac0bb3 100644 (file)
@@ -242,11 +242,6 @@ Job {
   Write Bootstrap = "/var/lib/bacula/%n.bsr"
   Priority = 15    # run after main backup
   Pool = "poolcatalog-<%=bacula_pool_name%>"
-  RunScript {
-    RunsWhen=After
-    RunsOnClient=No
-    Console = "purge volume action=all allpools storage=%w"
-  }
 }
 
 ########################################################################
index 7da723a5ab3c5c840c99c858af250c5300e09110..1755e62e9002a461b836812017d4821478ed6e14 100644 (file)
@@ -20,12 +20,6 @@ Job {
 
   Cancel Lower Level Duplicates = yes
   Cancel Queued Duplicates = yes
-
-  RunScript {
-    RunsWhen = After
-    RunsOnClient = No
-    Console = "purge volume action=all allpools storage=%w"
-  }
 }
 
 # Client (File Services) to backup