Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

#!/bin/bash

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

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 @gmail.com -s smtp.gmail.com:587 -xu user -xp pass -t mail@mail.ge -o tls=yes -u Tittle Full Backup -m Server Reports -a ${logfile}

exit

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

2 Answers 2

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
1  
...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... http://duplicity.nongnu.org/

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.