Recently Written · git

encrypted-home-backups

Automated home backups, onto an encrypted partition

git clone https://github.com/equwal/encrypted-home-backups

Log | Files | Refs


backup.pl (775 bytes)

1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 my $uuid = $ARGV[0];
5 my $keyfile = $ARGV[1];
6 my $user = $ARGV[2];
7 my $mountfolder = $ARGV[3];
8 # Put auto-dev-detect code here
9 my $last_half = '';
10 my $blkid = `blkid`;
11 for(split "\n", $blkid) {
12     print;
13     print "\n";
14     if(m#$uuid#) {
15         m#/dev/(.*):#;
16         $last_half = $1;
17         last;
18     }
19 }
20 if($last_half eq '') {
21     die "Failed to associate a dev device with that UUID.";
22 } else {
23     print "Last half: $last_half\n";
24 }
25 my $mount = "$mountfolder/$last_half";
26 `cryptsetup --key-file $keyfile luksOpen /dev/$last_half $last_half`;
27 `mkdir -p $mount`;
28 `mount /dev/mapper/$last_half $mount`;
29 # Do a home-only backup
30 my $date = `date`;
31 my $fname = "$mount/backup-$date";
32 `mkdir '$fname'`;
33 `cp -a /home/$user '$fname'`;