commit 78a0a92586d65c30657c36ab215f359cd625d61d Spenser Truex <spensertruexonline@gmail.com> 2019-04-02 15:17:47 -0700 Added installation and readme.
README.md | 32 ++++++++++++++++++++++++++++++++ backup | 29 ++--------------------------- backup.pl | 27 +++++++++++++++++++++++++++ install | 4 ++++ 4 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/README.md b/README.md new file mode 100644 index 0000000..d474f9b --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# Automatic encrypted /home backups + +# Install +Encrypt and install filesystems on the backup disk. + +``` shell +# lsblk +# parted /dev/sdb +> mktable +> mkpart +# cryptsetup luksFormat /dev/sdb1 +# cryptsetup luksOpen /dev/sdb1 sdb1 +# mkdir /mnt/sdb1 +# mount /dev/mapper/sdb1 /mnt/sdb1 +# mkfs.ext4 /mnt/sdb1 +# umount /dev/mapper/sdb1 +``` + +Modify the user-data bash file (`backup`) to fit your keyfile, UUID, username, +and mount folder. + +Keyfile should just be a plaintext file with the password for the disk. + +Get the uuid with `# blkid` on the partition. + +Username is for the folder to backup under `/home`. + +Mount folder cannot be in the `/home`. + +Execute it as root with the device plugged in. + +`# ./backup` diff --git a/backup b/backup index cd2cb89..7bbda6c 100755 --- a/backup +++ b/backup @@ -1,27 +1,2 @@ -#!/usr/bin/perl -use strict; -use warnings; -my $uuid = $ARGV[0]; -my $keyfile = $ARGV[1]; -print "Press any key when the device is plugged in.\n"; -getc(); -# Put auto-dev-detect code here -my $last_half; -my $blkid = `blkid`; -print "$blkid\n$uuid\n$keyfile"; -if($blkid =~ /(.*)$uuid.*/) { - print $1; - my $tmp = $1; - $tmp =~ m#/dev/(.*?):#; - $last_half = $1; -} else { - die "Could not get a device ID from that UUID." -} -my $mount = "/mnt/dev/$last_half"; -my $mapper = "/dev/mapper/$last_half"; -`cryptsetup --key-file $keyfile luksOpen /dev/$last_half $last_half`; -`mkdir -p $mount`; -`mount /dev/mapper/$last_half $mount`; -# Do a home-only backup -my $bname = `date`; -`tar -cjf '$mount/backup-$bname.tar.bz2' /home/jose`; +#!/bin/bash +backup.pl '64f91d6e-90e2-41d7-8494-bcb1d01b7b40' '/home/jose/bin/keyfile' 'jose' '/mnt' diff --git a/backup.pl b/backup.pl new file mode 100755 index 0000000..d7cda2b --- /dev/null +++ b/backup.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +use strict; +use warnings; +my $uuid = $ARGV[0]; +my $keyfile = $ARGV[1]; +my $user = $ARGV[2]; +my $mountfolder = $ARGV[3]; +# Put auto-dev-detect code here +my $last_half; +my $blkid = `blkid`; +print "$blkid\n$uuid\n$keyfile"; +if($blkid =~ /(.*)$uuid.*/) { + print $1; + my $tmp = $1; + $tmp =~ m#/dev/(.*?):#; + $last_half = $1; +} else { + die "Could not get a device ID from that UUID." +} +my $mount = "$mountfolder/dev/$last_half"; +my $mapper = "/dev/mapper/$last_half"; +`cryptsetup --key-file $keyfile luksOpen /dev/$last_half $last_half`; +`mkdir -p $mount`; +`mount /dev/mapper/$last_half $mount`; +# Do a home-only backup +my $bname = `date`; +`tar -cjf '$mount/backup-$bname.tar.bz2' /home/$user`; diff --git a/install b/install new file mode 100755 index 0000000..3f64eb1 --- /dev/null +++ b/install @@ -0,0 +1,4 @@ +#!/bin/bash +chown root backup +cp backup /usr/bin +cp backup.pl /usr/bin