Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bvfscommon.py « node « fuse « bareos - github.com/bareos/python-bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: adba72168719d76067dc4453e7a733e9fe31d03d (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Bareos specific Fuse node.
"""

from   bareos.fuse.node.base import Base
import logging
import os
import stat

class BvfsCommon(Base):
    XattrKeyRestoreTrigger = "user.bareos.do"
    XattrKeyRestoreJobId = "user.bareos.restore_job_id"
    
    def init(self, root, jobid, path, filename, stat):
        self.jobid = jobid
        self.static = True
        self.restorepath = os.path.normpath("/%s/jobid=%s/" % (self.root.restorepath, self.jobid))
        if filename:
            self.restorepathfull = os.path.normpath(u"%s%s%s" % (self.restorepath, path, filename))
        else:
            self.restorepathfull = os.path.normpath(u"%s%s" % (self.restorepath, path))
        self.xattr = {
                'user.bareos.restorepath': self.restorepathfull,
                'user.bareos.restored': 'no',
            }
        if self.root.restoreclient:
            # restore is only possible, if a restoreclient is given
            self.xattr['user.bareos.do_options'] = 'restore'
            self.xattr['user.bareos.do'] = ''

        if stat:
            self.set_stat(stat)            

    def listxattr(self, path):
        # update xattrs
        if self.xattr['user.bareos.restored'] != 'yes':
            if os.access(self.restorepathfull, os.F_OK):
                self.xattr['user.bareos.restored'] = 'yes'
        return super(BvfsCommon, self).listxattr(path)

    # Helpers
    # =======

    def restore(self, path, pathIds, fileIds):
        self.logger.debug( "%s: start", self.get_name() )
        bvfs_restore_id = "b20042"
        dirId=''
        if pathIds:
            dirId='dirid=' + ",".join(map(str, pathIds))
        fileId=''
        if fileIds:
            fileId='fileid=' + ",".join(map(str, fileIds))
        select = self.bsock.call(
            '.bvfs_restore jobid={jobid} {dirid} {fileid} path={bvfs_restore_id}'.format(
                jobid = self.jobid,
                dirid = dirId,
                fileid = fileId,
                bvfs_restore_id = bvfs_restore_id))
        restore = self.bsock.call(
            'restore file=?{bvfs_restore_id} client={client} restoreclient={restoreclient} where="{where}" yes'.format(
                client = self.job.job['client'],
                restoreclient = self.root.restoreclient,
                where = self.restorepath,
                bvfs_restore_id = bvfs_restore_id))
        try:
            restorejobid=restore['run']['jobid']
            self.setxattr(path, self.XattrKeyRestoreJobId, str(restorejobid), 0)
        except KeyError:
            self.logger.debug("failed to get resulting jobid of run command (maybe old version of Bareos Director)")
        cleanup = self.bsock.call('.bvfs_cleanup path={bvfs_restore_id}'.format(bvfs_restore_id = bvfs_restore_id))
        self.logger.debug( "%s: end", self.get_name() )