Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to put together bash script to backup whole system. This is my bash try so obviously I messed up something!


mybackupname="backup-fullsys-$(date +%Y-%m-%d).tar.gz"

echo Backup Started `date` >> ${logfile}

tar -cpzvf ${mybackupname} --exclude=/${mybackupname} --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev / >> ${logfile}

ls -gh ${mybackupname} >> ${logfile}

mv -v ${mybackupname} backups/filesystem/ >> ${logfile}

echo Backup Completed `date` >> ${logfile}

sendEmail -v -f -s -xu user -xp pass -t -o tls=yes -u Tittle Full Backup -m Server Reports -a ${logfile}


It was run using cron.

And on my email I received this:

-rw-r--r-- 1 root 965M Jul 13 16:11 backup-fullsys-2012-07-13.tar.gz
`backup-fullsys-2012-07-13.tar.gz' -> `backups/filesystem/'
Backup Completed Fri Jul 13 16:11:14 GET 2012

Now funny thing is that I thought bash script would run from my home directory. So path I included in script is backups/filesystem/. This folder does exist in /home/me/backups/filesystem/ and bash script is located in /home/me/bash.bash

I cannot find neither tar or log file! I tried to cd into folder, nothing.

I tried locate/find.

When I do df -h though I can see that something is taking space. My original partition was 2gb now it is 4gb so file is there somewhere.

share|improve this question
up vote 2 down vote accepted

In the mail, the owner of the file seems to be "root", so check into the "/root" folder instead of your home folder to see if there is something there.

share|improve this answer
haha! thank you. – Sandro Dzneladze Jul 13 '12 at 12:50
1 question, why I didn't get information about mv command fail? cause obviously in root folder backup dir doesn't exist. – Sandro Dzneladze Jul 13 '12 at 12:52
You redirect the standard output to your log file, to redirect the error output you shoud have used mv -v ${mybackupname} backups/filesystem/ 2>>${logfile} – epingle Jul 13 '12 at 12:54
...and to redirect both to the logfile mv -v ${mybackupname} backups/filesystem/ 2>&1 >>${logfile} (2>&1 means: redirect stderr to stdout, then >>${logfile} redirect both together to be appended to your logfile) – Izzy Jul 13 '12 at 13:01
@Izzy: The order should be the other way around: mv ... >> $logfile 2>&1 – Dennis Williamson Jul 14 '12 at 0:55

Any reason why your deciding to roll your own backup mechanism vs using something out there? There are some nice backup tools that do compression, store to a variety of places, handle full/incrementals, support cleaning up old backups, etc.

For example, Duplicity...

Just a thought... I never like to reinvent the wheel, unless it is for educational purposes :^)

share|improve this answer
yes learning purposes. I would not write webserver, but for simple applications I like doing them myself so I can learn a thing or two. – Sandro Dzneladze Jul 13 '12 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .