Beispiel #1
0
    localfs_split = localfs.split('/')

    if len(localfs_split) > 1:
        remotefs_final = "%s/%s" % (remotefs, "/".join(localfs_split[1:]))
        if len(localfs_split) > 2:
            remotefs_parent = "%s/%s" % (remotefs, "/".join(localfs_split[1:-1]))
        else:
            remotefs_parent = "%s/%s" % (remotefs, localfs_split[1])
    else:
        remotefs_final = remotefs
        remotefs_parent = remotefs

    # Test if there is work to do, if so, own them
    MNTLOCK.lock()
    syslog.syslog(syslog.LOG_DEBUG, "Checking dataset %s" % (localfs))
    zfsproc = pipeopen('/sbin/zfs list -Ht snapshot -o name,metanas:state -r -S creation -d 1 %s' % (localfs), debug)
    output, error = zfsproc.communicate()
    if zfsproc.returncode:
        syslog.syslog(syslog.LOG_ALERT,
            'Could not determine last available snapshot for dataset %s: %s'
            % (localfs, error, ))
        MNTLOCK.unlock()
        continue
    if output != '':
        snapshots_list = output.split('\n')
        found_latest = False
        for snapshot_item in snapshots_list:
            if snapshot_item != '':
                snapshot, state = snapshot_item.split('\t')
                if found_latest:
                    # assert (known_latest_snapshot != '') because found_latest
Beispiel #2
0
        tasklist = []
        if mp_to_task_map.has_key((fs, expire_time)):
            tasklist = mp_to_task_map[(fs, expire_time)]
            tasklist.append(task)
        else:
            tasklist = [task]
        mp_to_task_map[(fs, expire_time)] = tasklist

# Do not proceed further if we are not going to generate any snapshots for this run
if len(mp_to_task_map) == 0:
    exit()

# Grab all existing snapshot and filter out the expiring ones
snapshots = {}
snapshots_pending_delete = set()
zfsproc = pipeopen("/sbin/zfs list -t snapshot -H", debug)
lines = zfsproc.communicate()[0].split('\n')
reg_autosnap = re.compile('^auto-(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2}).(?P<hour>\d{2})(?P<minute>\d{2})-(?P<retcount>\d+)(?P<retunit>[hdwmy])$')
for line in lines:
    if line != '':
        snapshot_name = line.split('\t')[0]
        fs, snapname = snapshot_name.split('@')
        snapname_match = reg_autosnap.match(snapname)
        if snapname_match != None:
            snap_infodict = snapname_match.groupdict()
            snap_ret_policy = '%s%s' % (snap_infodict['retcount'], snap_infodict['retunit'])
            if snap_expired(snap_infodict, snaptime):
                snapshots_pending_delete.add(snapshot_name)
            else:
                if mp_to_task_map.has_key((fs, snap_ret_policy)):
                    if snapshots.has_key((fs, snap_ret_policy)):
Beispiel #3
0
    if len(localfs_split) > 1:
        remotefs_final = "%s/%s" % (remotefs, "/".join(localfs_split[1:]))
        if len(localfs_split) > 2:
            remotefs_parent = "%s/%s" % (remotefs, "/".join(
                localfs_split[1:-1]))
        else:
            remotefs_parent = "%s/%s" % (remotefs, localfs_split[1])
    else:
        remotefs_final = remotefs
        remotefs_parent = remotefs

    # Test if there is work to do, if so, own them
    MNTLOCK.lock()
    syslog.syslog(syslog.LOG_DEBUG, "Checking dataset %s" % (localfs))
    zfsproc = pipeopen(
        '/sbin/zfs list -Ht snapshot -o name,metanas:state -r -S creation -d 1 %s'
        % (localfs), debug)
    output, error = zfsproc.communicate()
    if zfsproc.returncode:
        syslog.syslog(
            syslog.LOG_ALERT,
            'Could not determine last available snapshot for dataset %s: %s' %
            (
                localfs,
                error,
            ))
        MNTLOCK.unlock()
        continue
    if output != '':
        snapshots_list = output.split('\n')
        found_latest = False
Beispiel #4
0
        tasklist = []
        if mp_to_task_map.has_key((fs, expire_time)):
            tasklist = mp_to_task_map[(fs, expire_time)]
            tasklist.append(task)
        else:
            tasklist = [task]
        mp_to_task_map[(fs, expire_time)] = tasklist

# Do not proceed further if we are not going to generate any snapshots for this run
if len(mp_to_task_map) == 0:
    exit()

# Grab all existing snapshot and filter out the expiring ones
snapshots = {}
snapshots_pending_delete = set()
zfsproc = pipeopen("/sbin/zfs list -t snapshot -H", debug)
lines = zfsproc.communicate()[0].split('\n')
reg_autosnap = re.compile(
    '^auto-(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2}).(?P<hour>\d{2})(?P<minute>\d{2})-(?P<retcount>\d+)(?P<retunit>[hdwmy])$'
)
for line in lines:
    if line != '':
        snapshot_name = line.split('\t')[0]
        fs, snapname = snapshot_name.split('@')
        snapname_match = reg_autosnap.match(snapname)
        if snapname_match != None:
            snap_infodict = snapname_match.groupdict()
            snap_ret_policy = '%s%s' % (snap_infodict['retcount'],
                                        snap_infodict['retunit'])
            if snap_expired(snap_infodict, snaptime):
                snapshots_pending_delete.add(snapshot_name)