Ejemplo n.º 1
0
def main(argv):
    o = Options(optspec)
    opt, flags, extra = o.parse_bytes(argv[1:])

    if not opt.unsafe:
        o.fatal(
            'refusing to run dangerous, experimental command without --unsafe')

    if len(extra) < 1:
        o.fatal('no paths specified')

    repo = from_opts(opt)
    bup_rm(repo, [argv_bytes(x) for x in extra], verbosity=opt.verbose)
    die_if_errors()
Ejemplo n.º 2
0
def main(argv):
    o = Options(optspec)
    opt, flags, extra = o.parse_bytes(argv[1:])

    if not opt.unsafe:
        o.fatal(
            'refusing to run dangerous, experimental command without --unsafe')

    if len(extra) < 1:
        o.fatal('no paths specified')

    check_repo_or_die()
    with LocalRepo() as repo:
        bup_rm(repo, [argv_bytes(x) for x in extra],
               compression=opt.compress,
               verbosity=opt.verbose)
    die_if_errors()
Ejemplo n.º 3
0
                    else:
                        log('keeping %s since %s\n' % (kind, epoch_ymd))

git.check_repo_or_die()

# This could be more efficient, but for now just build the whole list
# in memory and let bup_rm() do some redundant work.

removals = []
for branch, branch_id in branches(roots):
    die_if_errors()
    saves = git.rev_list(branch_id.encode('hex'))
    for keep_save, (utc, id) in classify_saves(saves, period_start):
        assert(keep_save in (False, True))
        # FIXME: base removals on hashes
        if opt.pretend:
            print('+' if keep_save else '-', save_name(branch, utc))
        elif not keep_save:
            removals.append(save_name(branch, utc))

if not opt.pretend:
    die_if_errors()
    bup_rm(removals, compression=opt.compress, verbosity=opt.verbose)
    if opt.gc:
        die_if_errors()
        bup_gc(threshold=opt.gc_threshold,
               compression=opt.compress,
               verbosity=opt.verbose)

die_if_errors()
Ejemplo n.º 4
0
def main(argv):
    o = options.Options(optspec)
    opt, flags, roots = o.parse_bytes(argv[1:])
    roots = [argv_bytes(x) for x in roots]

    if not opt.unsafe:
        o.fatal(
            'refusing to run dangerous, experimental command without --unsafe')

    now = int(time()) if opt.wrt is None else opt.wrt
    if not isinstance(now, int_types):
        o.fatal('--wrt value ' + str(now) + ' is not an integer')

    period_start = {}
    for period, extent in (('all', opt.keep_all_for), ('dailies',
                                                       opt.keep_dailies_for),
                           ('monthlies', opt.keep_monthlies_for),
                           ('yearlies', opt.keep_yearlies_for)):
        if extent:
            secs = period_as_secs(extent.encode('ascii'))
            if not secs:
                o.fatal('%r is not a valid period' % extent)
            period_start[period] = now - secs

    if not period_start:
        o.fatal('at least one keep argument is required')

    period_start = defaultdict(lambda: float('inf'), period_start)

    if opt.verbose:
        epoch_ymd = strftime('%Y-%m-%d-%H%M%S', localtime(0))
        for kind in ['all', 'dailies', 'monthlies', 'yearlies']:
            period_utc = period_start[kind]
            if period_utc != float('inf'):
                if not (period_utc > float('-inf')):
                    log('keeping all ' + kind)
                else:
                    try:
                        when = strftime('%Y-%m-%d-%H%M%S',
                                        localtime(period_utc))
                        log('keeping ' + kind + ' since ' + when + '\n')
                    except ValueError as ex:
                        if period_utc < 0:
                            log('keeping %s since %d seconds before %s\n' %
                                (kind, abs(period_utc), epoch_ymd))
                        elif period_utc > 0:
                            log('keeping %s since %d seconds after %s\n' %
                                (kind, period_utc, epoch_ymd))
                        else:
                            log('keeping %s since %s\n' % (kind, epoch_ymd))

    git.check_repo_or_die()

    # This could be more efficient, but for now just build the whole list
    # in memory and let bup_rm() do some redundant work.

    def parse_info(f):
        author_secs = f.readline().strip()
        return int(author_secs)

    sys.stdout.flush()
    out = byte_stream(sys.stdout)

    removals = []
    for branch, branch_id in branches(roots):
        die_if_errors()
        saves = ((utc, unhexlify(oidx)) for (
            oidx,
            utc) in git.rev_list(branch_id, format=b'%at', parse=parse_info))
        for keep_save, (utc, id) in classify_saves(saves, period_start):
            assert (keep_save in (False, True))
            # FIXME: base removals on hashes
            if opt.pretend:
                out.write((b'+ ' if keep_save else b'- ') +
                          save_name(branch, utc) + b'\n')
            elif not keep_save:
                removals.append(save_name(branch, utc))

    if not opt.pretend:
        die_if_errors()
        repo = LocalRepo()
        bup_rm(repo, removals, compression=opt.compress, verbosity=opt.verbose)
        if opt.gc:
            die_if_errors()
            bup_gc(threshold=opt.gc_threshold,
                   compression=opt.compress,
                   verbosity=opt.verbose)

    die_if_errors()
Ejemplo n.º 5
0
                    else:
                        log('keeping %s since %s\n' % (kind, epoch_ymd))

git.check_repo_or_die()

# This could be more efficient, but for now just build the whole list
# in memory and let bup_rm() do some redundant work.

removals = []
for branch, branch_id in branches(roots):
    die_if_errors()
    saves = git.rev_list(branch_id.encode('hex'))
    for keep_save, (utc, id) in classify_saves(saves, period_start):
        assert(keep_save in (False, True))
        # FIXME: base removals on hashes
        if opt.pretend:
            print('+' if keep_save else '-', save_name(branch, utc))
        elif not keep_save:
            removals.append(save_name(branch, utc))

if not opt.pretend:
    die_if_errors()
    bup_rm(removals, compression=opt.compress, verbosity=opt.verbose)
    if opt.gc:
        die_if_errors()
        bup_gc(threshold=opt.gc_threshold,
               compression=opt.compress,
               verbosity=opt.verbose)

die_if_errors()
Ejemplo n.º 6
0
from bup.git import check_repo_or_die
from bup.options import Options
from bup.helpers import die_if_errors, handle_ctrl_c, log
from bup.repo import LocalRepo
from bup.rm import bup_rm

optspec = """
bup rm <branch|save...>
--
#,compress=  set compression level to # (0-9, 9 is highest) [6]
v,verbose    increase verbosity (can be specified multiple times)
unsafe       use the command even though it may be DANGEROUS
"""

handle_ctrl_c()

o = Options(optspec)
opt, flags, extra = o.parse(sys.argv[1:])

if not opt.unsafe:
    o.fatal('refusing to run dangerous, experimental command without --unsafe')

if len(extra) < 1:
    o.fatal('no paths specified')

check_repo_or_die()
repo = LocalRepo()
bup_rm(repo, extra, compression=opt.compress, verbosity=opt.verbose)
die_if_errors()
Ejemplo n.º 7
0
from bup.options import Options
from bup.helpers import die_if_errors, handle_ctrl_c, log
from bup.repo import LocalRepo
from bup.rm import bup_rm

optspec = """
bup rm <branch|save...>
--
#,compress=  set compression level to # (0-9, 9 is highest) [6]
v,verbose    increase verbosity (can be specified multiple times)
unsafe       use the command even though it may be DANGEROUS
"""

handle_ctrl_c()

o = Options(optspec)
opt, flags, extra = o.parse(sys.argv[1:])

if not opt.unsafe:
    o.fatal('refusing to run dangerous, experimental command without --unsafe')

if len(extra) < 1:
    o.fatal('no paths specified')

check_repo_or_die()
repo = LocalRepo()
bup_rm(repo, [argv_bytes(x) for x in extra],
       compression=opt.compress,
       verbosity=opt.verbose)
die_if_errors()
Ejemplo n.º 8
0
Archivo: rm-cmd.py Proyecto: bup/bup
from bup.git import check_repo_or_die
from bup.options import Options
from bup.helpers import die_if_errors, handle_ctrl_c, log
from bup.repo import LocalRepo
from bup.rm import bup_rm

optspec = """
bup rm <branch|save...>
--
#,compress=  set compression level to # (0-9, 9 is highest) [6]
v,verbose    increase verbosity (can be specified multiple times)
unsafe       use the command even though it may be DANGEROUS
"""

handle_ctrl_c()

o = Options(optspec)
opt, flags, extra = o.parse(sys.argv[1:])

if not opt.unsafe:
    o.fatal('refusing to run dangerous, experimental command without --unsafe')

if len(extra) < 1:
    o.fatal('no paths specified')

check_repo_or_die()
repo = LocalRepo()
bup_rm(repo, extra, compression=opt.compress, verbosity=opt.verbose)
die_if_errors()