Bash Script to Back Up Backs Up Itself
Posted
by
Jay LaCroix
on Super User
See other posts from Super User
or by Jay LaCroix
Published on 2012-11-23T15:17:35Z
Indexed on
2012/11/23
17:09 UTC
Read the original article
Hit count: 436
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
© Super User or respective owner