Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschulz committed Dec 2, 2012
0 parents commit e7ac629
Show file tree
Hide file tree
Showing 22 changed files with 1,811 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
@@ -0,0 +1,14 @@
blib*
.build/
Makefile
Makefile.old
Build
Build.bat
_build*
pm_to_blib*
*.tar.gz
.lwpcookies
cover_db
pod2htm*.tmp
Sys-RevoBackup-*
Debian_CPANTS.txt
4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for Sys-RevoBackup

0.16 2012-12-02
First public version, released on an unsuspecting world.
31 changes: 31 additions & 0 deletions README.md
@@ -0,0 +1,31 @@
This is the README file for Sys-Revobackup,
an rsync-based backup script.

## Description

Sys-Revobackup provides an rsync-based backup script.

## Installation

This package uses Dist::Zilla.

Use

dzil build

to create a release tarball which can be
unpacked and installed like any other EUMM
distribution.

perl Makefile.PL

make

make test

make install

## Documentation

Please see perldoc Sys::Revobackup.

20 changes: 20 additions & 0 deletions bin/revobackup.pl
@@ -0,0 +1,20 @@
#!/usr/bin/perl
# ABSTRACT: rsync based backup script
# PODNAME: revobackup.pl
use strict;
use warnings;

use Sys::RevoBackup::Cmd;

my $Cmd = Sys::RevoBackup::Cmd::->new();
$Cmd->run();

exit 1;

__END__
=head1 NAME
revobackup - rsync based backup
=cut
52 changes: 52 additions & 0 deletions dist.ini
@@ -0,0 +1,52 @@
name = Sys-RevoBackup
author = Dominik Schulz <dominik.schulz@gauner.org>
license = Perl_5
copyright_holder = Dominik Schulz
copyright_year = 2012

version = 0.16

[GatherDir]
exclude_filename = README.pod
exclude_match = ^doc.*
exclude_match = ^cover.*

[PruneCruft]
[Authority]
[PkgVersion]
[MetaJSON]

[ExtraTests]
[PodSyntaxTests]
[NoTabsTests]
[EOLTests]

[Manifest]
[MakeMaker]

[AutoPrereqs]
[Prereqs / BuildRequires]
[Prereqs]
[Prereqs / Recommends]

[Git::CheckFor::CorrectBranch]
release_branch = master

[@Git]
tag_format = version_%v

[GitHub::Meta]
repo = Sys-RevoBackup

[Twitter]
hash_tags = #cpan

[PodWeaver]

[MetaYAML]
[License]
[ReadmeFromPod]

[CheckChangeLog]
[ConfirmRelease]
[UploadToCPAN]
189 changes: 189 additions & 0 deletions lib/Sys/RevoBackup.pm
@@ -0,0 +1,189 @@
package Sys::RevoBackup;
# ABSTRACT: an rsync-based backup script

use 5.010_000;
use mro 'c3';
use feature ':5.10';

use Moose;
use namespace::autoclean;

# use IO::Handle;
# use autodie;
# use MooseX::Params::Validate;
use English qw( -no_match_vars );
use Try::Tiny;

use Sys::Run;
use Job::Manager;
use Sys::RevoBackup::Job;

extends 'Sys::Bprsync';

has 'bank' => (
'is' => 'ro',
'isa' => 'Str',
'required' => 1,
);

has 'sys' => (
'is' => 'rw',
'isa' => 'Sys::Run',
'lazy' => 1,
'builder' => '_init_sys',
);

with qw(Config::Yak::OrderedPlugins);

sub _plugin_base_class { return 'Sys::RevoBackup::Plugin'; }

sub _init_sys {
my $self = shift;

my $Sys = Sys::Run::->new( { 'logger' => $self->logger(), } );

return $Sys;
}

sub _init_config_prefix {
return 'Sys::RevoBackup';
}

sub _init_jobs {
my $self = shift;

my $JQ = Job::Manager::->new(
{
'logger' => $self->logger(),
'concurrency' => $self->concurrency(),
}
);

my $verbose = $self->config()->get( $self->config_prefix() . '::Verbose' ) ? 1 : 0;
my $dry = $self->config()->get( $self->config_prefix() . '::Dry' ) ? 1 : 0;

foreach my $job_name ( @{$self->vaults()} ) {
try {
my $Job = Sys::RevoBackup::Job::->new(
{
'parent' => $self,
'name' => $job_name,
'verbose' => $verbose,
'logger' => $self->logger(),
'config' => $self->config(),
'bank' => $self->bank(),
'vault' => $job_name,
'dry' => $dry,
}
);
$JQ->add($Job);
}
catch {
$self->logger()->log( message => 'caught error: '.$_, level => 'error', );
};
}

return $JQ;
}

sub vaults {
my $self = shift;

return [$self->config()->get_array( $self->config_prefix() . '::Vaults' )];
}

sub run {
my $self = shift;

foreach my $Plugin (@{$self->plugins()}) {
try {
$Plugin->run_config_hook();
} catch {
$self->logger()->log( message => 'Failed to run config hook of plugin '.ref($Plugin).' w/ error: '.$_, level => 'error', );
};
}

foreach my $Plugin (@{$self->plugins()}) {
try {
$Plugin->run_prepare_hook();
} catch {
$self->logger()->log( message => 'Failed to run prepare hook of plugin '.ref($Plugin).' w/ error: '.$_, level => 'error', );
};
}

if ( !$self->_exec_pre() ) {
$self->_cleanup(0);
}
if ( $self->jobs()->run() ) {
$self->_cleanup(1);
$self->_exec_post();
return 1;
}
else {
return;
}
}

sub _cleanup {
my $self = shift;
my $ok = shift;

foreach my $Plugin (@{$self->plugins()}) {
try {
$Plugin->run_cleanup_hook($ok);
} catch {
$self->logger()->log( message => 'Failed to run cleanup hook of plugin '.ref($Plugin).' w/ error: '.$_, level => 'error', );
};
}

return 1;
}

no Moose;
__PACKAGE__->meta->make_immutable;

1;

__END__
=head1 CONFIGURATION
Place the configuration inside /etc/revobackup/revobackup.conf
<VTK>
<RevoBackup>
bank = /srv/backup/bank
<Rotations>
daily = 10
weekly = 4
monthly = 12
yearly = 10
</Rotations>
<Vaults>
<test001>
source = /home/
description = Uhm
hardlink = 1
nocrossfs = 1
</test001>
<anotherhost>
source = anotherhost:/
description = Backup anotherhost
</anotherhost>
</Vaults>
</RevoBackup>
</VTK>
=head1 NAME
Sys::RevoBackup - Rsync based backup script
=method run
Run the backups.
=method vaults
Return a list of all vaults (i.e. backup jobs).
=cut
43 changes: 43 additions & 0 deletions lib/Sys/RevoBackup/Cmd.pm
@@ -0,0 +1,43 @@
package Sys::RevoBackup::Cmd;
# ABSTRACT: revobackup CLI

use 5.010_000;
use mro 'c3';
use feature ':5.10';

use Moose;
use namespace::autoclean;

# use IO::Handle;
# use autodie;
# use MooseX::Params::Validate;
# use Carp;
# use English qw( -no_match_vars );
# use Try::Tiny;

# extends ...
extends 'MooseX::App::Cmd';
# has ...
# with ...
# initializers ...

# your code here ...

no Moose;
__PACKAGE__->meta->make_immutable;

1;

__END__
=head1 NAME
Sys::RevoBackup::Cmd - Command base class.
=head1 DESCRIPTION
This class is the base class for any command implemented by its subclasses.
It is a mere requirement by App::Cmd. Don't mess with it.
=cut

0 comments on commit e7ac629

Please sign in to comment.