Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-21-2009, 11:22 PM   #1
LQ Newbie
Registered: Jul 2009
Posts: 1

Rep: Reputation: 0
Backup script

Hey there,

I'm attempting to create a shell script using Ubuntu that will take one optional argument (which in this case is a path to a directory to backup) and will back up (by using the tar command) the chosen directory which is the /home. And i want, after tar'ing the home directory, for it to save the output in /var/backups with the file name as the date.

I'm very new to this so I was just hoping I could get pointed in the right direction!

Old 07-21-2009, 11:43 PM   #2
Registered: Oct 2004
Location: Adelaide Hills, South Australia
Distribution: RHEL 5&6 CentOS 5, 6 & 7
Posts: 572

Rep: Reputation: 56
This should get you started:-

if [ -z "$1" ]; then
  echo You need to pass a parameter.
  exit 1

tar -cvzf /var/backups/$(date +%F).tgz $1
Old 07-22-2009, 12:00 AM   #3
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
i also suggest that you add a test if the argument is an existing directory:

if [ ! -d "$1" ]; then
  echo "Specified argument is not a directory."
  exit 1


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
Backup Script Help Canni Programming 8 06-15-2006 10:19 AM
What backup script do you use? buldir Linux - Software 1 04-12-2005 02:57 PM
backup script wiltzius Linux - Software 8 03-23-2005 05:12 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration