LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 07-21-2009, 11:22 PM   #1
nasser00
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!

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

Rep: Reputation: 61
This should get you started:-
Code:
#!/bin/bash

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

tar -cvzf /var/backups/$(date +%F).tgz $1
 
Old 07-22-2009, 12:00 AM   #3
konsolebox
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:

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


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:11 PM.

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