summaryrefslogtreecommitdiff
path: root/tarsnap/daily_tarsnap.pl
blob: 420c3657856dc23da616602d8b69c5129cd40cb2 (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
#!/usr/bin/env perl
use v5.32;
use strict;
use DateTime;

my $ip_out = `ip -4 addr show`;
die 'not actual b7j0c.org; not running' unless ($ip_out =~ /inet 144.202.72.212/);

my $dt = DateTime->now();
$dt->set_time_zone('America/Chicago');
my $prefix = 'b7j0cdebian_';
my $prefix_yyyymmdd = $prefix . $dt->ymd('');
my $prefix_reserve_yyyymmdd = $prefix . $dt->subtract('days'=>1)->ymd('');
say "today:\t\t" . $prefix_yyyymmdd;
say "yesterday:\t" . $prefix_reserve_yyyymmdd;
my $tarsnap = 'tarsnap --cachedir /root/tarsnap-cache --keyfile /root/tarsnap.key';
my $list_archives = `$tarsnap --list-archives`;
my $backup_paths = '/home /var/www';
my $excludes = '';
chomp($list_archives);
my @archives = split(/\n/,$list_archives);
my $make_yyyymmdd = 1;
my @delete_these = ();
for my $archive (@archives) {
    say "list:\t\t" . $archive;
    if ($archive eq $prefix_yyyymmdd) {
        $make_yyyymmdd = 0;
    }
}
my $tarsnap_cmd = '';
if (1 == $make_yyyymmdd) {
    say "make for today";
    my $yyyymmdd_cmd = $tarsnap . ' -c -f ' . $prefix_yyyymmdd . ' ' . $backup_paths . ' ' . $excludes;
    say $yyyymmdd_cmd;
    $tarsnap_cmd = $yyyymmdd_cmd . ';';
}
say $tarsnap_cmd;
system($tarsnap_cmd) if ($tarsnap_cmd ne '');
1;