Skip to content

Instantly share code, notes, and snippets.

@Thrilleratplay
Created April 10, 2018 23:01
Show Gist options
  • Save Thrilleratplay/40ff7a8ff62402ad6f0f6e0171eb0c76 to your computer and use it in GitHub Desktop.
Save Thrilleratplay/40ff7a8ff62402ad6f0f6e0171eb0c76 to your computer and use it in GitHub Desktop.
Duplicity backup script
#!/bin/bash
EXCLUDED_PATHS=(
/tmp
/proc
/sys
/run
/var/log/journal/
)
####################################################################################
DEVICE_PARTITION="sdb1"
MAPPER_NAME="vgcrypt--backup-root"
LUKS_NAME="luks-backup"
MOUNT_DIR="/mnt/backup/"
BACKUP_PATH=$MOUNT_DIR`hostname | tr '[:upper:]' '[:lower:]'`
EXCLUDED_ARGS=`printf "%s%s" "${EXCLUDED_PATHS[@]/#/' --exclude '}"`
#######################################################################################
### Creation commands: DO NOT RUN AS A SCRIPT
# fdisk /dev/sdb
# cryptsetup -c aes-xts-plain64 -y --use-random luksFormat /dev/$DEVICE_PARTITION
# pvcreate /dev/mapper/$LUKS_NAME
# vgcreate vgcrypt-backup /dev/mapper/$LUKS_NAME
# lvcreate -l +100%FREE vgcrypt-backup --name root
# cryptsetup luksOpen /dev/$DEVICE_PARTITION $LUKS_NAME
# mkfs.ext4 /dev/mapper/vgcrypt--backup-root
# mkdir $BACKUP_PATH
# mount /dev/mapper/vgcrypt--backup-root /mnt/backup/
####################################################################################
if [ $(mount | grep $MAPPER_NAME | wc -c) -eq 0 ] ; then
if [ -e /dev/$DEVICE_PARTITION ] ; then
cryptsetup luksOpen /dev/$DEVICE_PARTITION $LUKS_NAME
sleep 2
mount /dev/mapper/$MAPPER_NAME $MOUNT_DIR
else
echo "can't find /dev/$DEVICE_PARTITION"
exit 1;
fi
fi
if [ $(mount | grep $MAPPER_NAME | wc -c) -ne 0 ]; then
### RUN FIRST TIME TO CREATE A FULL BACKUP
# duplicity full --progress --no-encryption --exclude-device-files $EXCLUDED_ARGS / file://$BACKUP_PATH
### Incremental
duplicity incremental --progress --no-encryption --exclude-device-files $EXCLUDED_ARGS / file://$BACKUP_PATH
umount $MOUNT_DIR
if [ $(mount | grep $MAPPER_NAME | wc -c) -eq 0 ] ; then
echo "$MAPPER_NAME has been unmounted"
else
echo "$MAPPER_NAME IS STILL MOUNTED"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment