Bash Script to Back Up Backs Up Itself
- by Jay LaCroix
I have the following bash script that creates a tar.gz of my filesystem on a Kubuntu PC. The problem is, that it also tries to backup the tar.gz backup file, even though I am storing the backup in /tmp and omitting /tmp from the backup. I am wondering why it's backing up the file in /tmp even though I told it not to.
#!/bin/bash
# init
DATE=$(date +20%y%m%d)
sudo tar -cvpzf /tmp/`hostname`_$DATE.tar.gz \
--exclude=/proc \
--exclude=/lost+found \
--exclude=/sys \
--exclude=/mnt \
--exclude=/media \
--exclude=/dev \
--exclude=/tmp \
--exclude=/home/jlacroix/Desktop \
--exclude=/home/jlacroix/Documents \
--exclude=/home/jlacroix/Music \
--exclude=/home/jlacroix/Pictures \
--exclude=/home/jlacroix/Projects \
--exclude=/home/jlacroix/Roms \
--exclude=/home/jlacroix/Videos \
--exclude=/home/jlacroix/.VirtualBox\ VMs \
--exclude=/home/jlacroix/.SpiderOak \
/
scp /tmp/`hostname`_$DATE.tar.gz jlacroix@Pluto:/share/Recovery/Snapshots
sudo rm /tmp/`hostname`_$DATE.tar.gz