Skip to content

Instantly share code, notes, and snippets.

@autarch
Created September 25, 2017 15:36
Show Gist options
  • Select an option

  • Save autarch/aa42e75efd89969315f024249e6fcf9d to your computer and use it in GitHub Desktop.

Select an option

Save autarch/aa42e75efd89969315f024249e6fcf9d to your computer and use it in GitHub Desktop.
#!/home/autarch/perl5/perlbrew/perls/perl-5.24.1/bin/perl
use strict;
use warnings;
use autodie;
use lib '/home/autarch/.perlbrew/libs/perl-5.24.1@system/lib/perl5';
use File::Find::Rule;
use Getopt::Long;
use Path::Class qw( dir );
my $verbose;
my $dry;
GetOptions(
'v' => \$verbose,
'dry' => \$dry,
);
my $root = dir('/home/autarch/mnt/backup/houseabsolute.urth.org');
backup_home();
backup_etc();
sub backup_home {
my @exclude = (
'#*#',
'*/Application Cache',
'.*#',
'/.mozilla/firefox/Crash Reports',
'/Ubuntu One',
'VirtualBox VMs',
qw(
*.tar.gz
*.tgz
*/.precomp
*/.r2
*/.tidyall.d
*/blib
*/cache
*~
/.CAAN-mason
/.PerlySense
/.Rapport*
/.Skype
/.VirtualBox
/.adobe
/.amazonmp3
/.android
/.beagle
/.build
/.caat
/.cache
/.cargo
/.color
/.composer
/.config/discord/Cache
/.config/discord/GPUCache
/.config/Slack/Cache
/.cpan
/.cpanm
/.cpanplus
/.cups
/.cvs
/.dbus
/.dia
/.dropbox*
/.fontconfig
/.frictionalgames
/.gem
/.gimp*
/.gstreamer-*
/.gtkpod
/.gvfs
/.icedtea
/.java
/.local/share/.cpan
/.local/share/Steam
/.macromedia
/.mozilla/eclipse
/.mozilla/firefox/*.parentlock
/.mozilla/firefox/*/Cache
/.mozilla/firefox/*/lock
/.nautilus
/.netflix-desktop
/.node-gyp
/.npm
/.nvm
/.perlbrew
/.perl-cpm
/.pulse
/.purple/icons
/.rakudobrew
/.rvm
/.silki
/.steam
/.svn
/.tarsnap/cache
/.thumbnails
/.vegguide
/.vnc
/.wine
/.xsession*
/.zeitgeist
/Downloads
/Dropbox
/Games
/Mail
/Music
/Podcasts
/Public
/Templates
/Videos
/android-sdk-linux
/backup
/bin/ec2-api-tools
/bin/vuze.bak
/caa/caa-video-uncompressed.avi
/caa/videos-for-shannon
go/src/github.maxmind.com
/isos
/jmeter
/libgeoip
/local-lib
/mnt
/mp3
/my-p3-env
/obnam-backup
/old
/perl5
/projects/DateTime-Locale/source-data
/projects/DateTime-TimeZone/DateTime-TimeZone-*
/projects/DateTime-TimeZone/t/zd*
/projects/Locale-CLDR/cldr-data/
/projects/perl2
/projects/perl2010**
/projects/perlweb
/projects/*/.build
/projects/reference
/tmp
/video
/vmware
_build
node_modules
nytprof*
)
);
push @exclude, '/.config/google-chrome/Profile*/Local Storage';
push @exclude, map { q{/} . $_ }
grep { !m{^work/admin} }
grep { $_ ne 'work' }
map {s{^/home/autarch/}{}r}
File::Find::Rule->directory()->maxdepth(1)->in('/home/autarch/work');
push @exclude, map { q{/} . $_ }
grep { m{/([^/]+)/\1-} || /\.tar\.gz$/ }
map {s{^/home/autarch/}{}r}
File::Find::Rule->name(qr/\w+-\d+\.\d+/)
->in('/home/autarch/projects');
_rsync(
'/home/autarch/',
$root->subdir('home'),
\@exclude,
);
}
sub backup_etc {
_rsync(
'/etc/',
$root->subdir('etc'),
);
}
sub _rsync {
my $source = shift;
my $target = shift;
my $exclude = shift;
$target->mkpath( 0, 0700 ) unless $dry || -d $target;
my @switches = (
'-a',
'--delete-excluded',
'--delete',
'-l',
'-x',
);
push @switches, '-v', '--progress' if $verbose;
my @command = (
'rsync',
@switches,
'-z',
(
map { ( '--exclude', $_ ) } sort { $a cmp $b } @{ $exclude || [] }
),
$source => $target
);
print "@command\n\n" if $verbose;
unless ($dry) {
system(@command)
and warn "Cannot rsync to $target: $!";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment