summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Admin/Backup.py
blob: 3744abca389d78d0e19a5fee90496c707d87185d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import sys
import time
import tarfile
import Bcfg2.Server.Admin
import Bcfg2.Options


class Backup(Bcfg2.Server.Admin.MetadataCore):
    __shorthelp__ = "Make a backup of the Bcfg2 repository"
    __longhelp__ = (__shorthelp__ + "\n\nbcfg2-admin backup\n")
                                    #"\n\nbcfg2-admin backup restore")
    __usage__ = ("bcfg2-admin backup")

    def __call__(self, args):
        Bcfg2.Server.Admin.MetadataCore.__call__(self, args)
        self.datastore = self.setup['repo']
        timestamp = time.strftime('%Y%m%d%H%M%S')
        format = 'gz'
        mode = 'w:' + format
        filename = timestamp + '.tar' + '.' + format
        out = tarfile.open(self.datastore + '/' + filename, mode=mode)
        out.add(self.datastore, os.path.basename(self.datastore))
        out.close()
        print("Archive %s was stored under %s" % (filename, self.datastore))