1

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 [email protected] -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.

2 Answers 2

1

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.

4
  • 1 question, why I didn't get information about mv command fail? cause obviously in root folder backup dir doesn't exist.
    – user98645
    Jul 13, 2012 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}
    – Flinth
    Jul 13, 2012 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, 2012 at 13:01
  • @Izzy: The order should be the other way around: mv ... >> $logfile 2>&1 Jul 14, 2012 at 0:55
1

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 :^)

1
  • 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.
    – user98645
    Jul 13, 2012 at 14:38

You must log in to answer this question.