LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-19-2009, 10:19 AM   #1
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Rep: Reputation: 0
need backup script please


hello people i am in need of linux help. iam at college and i need this back/restore script to pass this final part of an assessment. i require a backup script that will not only backup but also restore files to the relevent directories. e.g. users are instructed to store all wordprocessor files in a directory named wp. so i am needing to create a backup directory and 3 directories within that and some files within the 3 directories and then back them up ot restore them. l know i should/have to do this myself by been trying to get/understand info for the last few days and came up with zero. so i am pleading with some one out there for help.
thank you
 
Old 12-19-2009, 10:25 AM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by marydoll View Post
hello people i am in need of linux help. iam at college and i need this back/restore script to pass this final part of an assessment. i require a backup script that will not only backup but also restore files to the relevent directories. e.g. users are instructed to store all wordprocessor files in a directory named wp. so i am needing to create a backup directory and 3 directories within that and some files within the 3 directories and then back them up ot restore them. l know i should/have to do this myself by been trying to get/understand info for the last few days and came up with zero. so i am pleading with some one out there for help.
thank you
Post what you have written so far and we can help
 
Old 12-19-2009, 10:38 AM   #3
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
that is the problem i do not know what to write even after looking at all the sites and books, the only thing i know how to do is the directories and files, and i will understand that i wont learn anything if people do the work for me but i genuinely do not know what to do. my lecturer just says problem solve it or fail but i cant problem solve it if i canr=t write and undertsand it. sorry for this but i do really need this.
thanks
 
Old 12-19-2009, 10:39 AM   #4
~sHyLoCk~
Senior Member
 
Registered: Jul 2008
Location: /dev/null
Posts: 1,173
Blog Entries: 12

Rep: Reputation: 129Reputation: 129
Both backup and restore operations can be done using "cp".

Quote:
man cp
Regards
 
Old 12-19-2009, 10:56 AM   #5
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
sorry only ever used cp to copy files but should have added lecturer sowed a working example (but without showing the script). 1 backup 2. restore. 3. quit. he said something similar to that so onlyway i can describe it would be interactive, sorry if this confuses or makes the script harde for what i require but this is confusing me too.
 
Old 12-19-2009, 11:27 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
marydoll, LQ doesn't respond well to "please help me, this is really hard for me" so you are unlikely to solve your problem with your current approach.

LQ is best at helping people to help themselves and to gain an understanding of Linux.

Your best tactic will be to try and recall what you learned on the course, check out some shell scripting introductions (plenty there if you netsearch or use LQ's search). A script is just a collection of commands in a file so you can experiment on the command line to familiarise yourself with the tools you need.

All computer languages are ways of communicating with a machine. Machines have no imagination so need to be told exactly what to do. The only way you are going to be able to do that is if you can think very clearly about what you want the machine to do -- in terms of directories and files for this assignment.

Make a start. Tell what you have thought and show what you have tried, then LQ is likely to help; not before.
 
Old 12-19-2009, 11:53 AM   #7
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
i have downloaded the backup script from here http://www.intuitive.com/wicked/wick...-library.shtml and ran this script via college vm
Code:
#!/bin/sh

# Backup - create either a full or incremental backup of a set of
#     defined directories on the system. By default, the output 
#     file is saved in /tmp with a timestamped filename, compressed.
#     Otherwise, specify an output device (another disk, a removable).

usageQuit()
{
  cat << "EOF" >&2
Usage: $0 [-o output] [-i|-f] [-n]
  -o lets you specify an alternative backup file/device
  -i is an incremental or -f is a full backup, and -n prevents
  updating the timestamp if an incremental backup is done.
EOF
  exit 1
}

compress="bzip2"	# change for your favorite compression app
inclist="/tmp/backup.inclist.$(date +%d%m%y)"
 output="/tmp/backup.$(date +%d%m%y).bz2"
 tsfile="$HOME/.backup.timestamp"
  btype="incremental"	# default to an incremental backup
  noinc=0			#   and an update of the timestamp

trap "/bin/rm -f $inclist" EXIT

while getopts "o:ifn" opt; do
  case "$arg" in
    o ) output="$OPTARG";  	;;
    i ) btype="incremental";	;;
    f ) btype="full";		;;
    n ) noinc=1;		;;
    ? ) usageQuit		;;
  esac
done

shift $(( $OPTIND - 1 ))

echo "Doing $btype backup, saving output to $output"

timestamp="$(date +'%m%d%I%M')"

if [ "$btype" = "incremental" ] ; then 
  if [ ! -f $tsfile ] ; then
    echo "Error: can't do an incremental backup: no timestamp file" >&2
    exit 1
  fi
  find $HOME -depth -type f -newer $tsfile -user ${USER:-LOGNAME} | \
    pax -w -x tar | $compress > $output
  failure="$?"
else
  find $HOME -depth -type f -user ${USER:-LOGNAME} | \
    pax -w -x tar | $compress > $output
  failure="$?"
fi

if [ "$noinc" = "0" -a "$failure" = "0" ] ; then
  touch -t $timestamp $tsfile
fi

exit 0
and that came back with errors
Quote:
Doing incremental backup, saving output to /tmp/backup.191209.bz21
Error: can't do an incremental backup: no timestamp file
and in class we only got handed out a book with basic examples similar to the "hello world" script that seems to be on all web site tutorials, i would love to do this myself but i do not understand it to do it. not from a programming background (never even knew how to switch on a pc until 3 years ago)
 
Old 12-19-2009, 11:55 AM   #8
cpplinux
Member
 
Registered: Dec 2009
Posts: 37

Rep: Reputation: 17
You may try rsync. There are also some other tools to sync-tree. I did some search for you and here is the wiki page of rsync. At the end of it, there is an example of how to use rsync to do backup.
 
Old 12-19-2009, 12:02 PM   #9
AutoBot
Member
 
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184

Rep: Reputation: 34
Your teacher should be pointing you guys to this free ebook "Advanced Bash Scripting Guide" that pretty much can get you from bash zero to hero in one night if your technically savvy. We won't do your work for you as that would be cheating, we can help with a script that you create.
 
Old 12-19-2009, 12:05 PM   #10
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
cant use sofwtware to try ubuntu iso would not load (pc would not read disk) using college's vm to test, thanks for suggestion.
 
Old 12-19-2009, 12:06 PM   #11
AutoBot
Member
 
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184

Rep: Reputation: 34
To run that script you posted you need to run it with -n or -f to function properly.
 
Old 12-19-2009, 12:13 PM   #12
kofucii
Member
 
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62

Rep: Reputation: 20
Here simple one, using cpio:
Code:
ARG1=$1
ARG2=$2
ARG3=$3


DOBACKUP () {

find $ARG2 -depth -print | cpio -ocv > $ARG3
}

DORESTORE () {

cat $ARG2 | cpio -icvBumd
}

USAGE () {
printf "
-b <backup-dir> <output-file>  # point dir for backup and output file
-r <backup-file>               # restore from backup file
"
}


case $ARG1 in

-b)
DOBACKUP
exit 0
;;
-r)
DORESTORE
exit 0
;;
*)
USAGE
exit 0
;;
esac
for backup run;
<this script> -b <dir to backup> <output file>
for restore run:
<this script> -r <backup-file>
 
Old 12-19-2009, 12:14 PM   #13
marydoll
LQ Newbie
 
Registered: Dec 2009
Posts: 12

Original Poster
Rep: Reputation: 0
ran the script -n just goes to command prompt again (dont even know if its meant to do that)
ran it with -f and get sam message as before but different filename
Quote:
Doing incremental backup, saving output to /tmp/backup.191209.bz2
Error: can't do an incremental backup: no timestamp file
 
Old 12-19-2009, 12:46 PM   #14
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Quote:
ran the script -n just goes to command prompt again (dont even know if its meant to do that)
ran it with -f and get sam message as before but different filename
If you don't know what the script is doing, don't use it.
Start from scratch, and use the things you know from class.
No teacher will believe you made the script.
You will not learn, when you just copy stuff from other people.
 
Old 12-19-2009, 02:07 PM   #15
AutoBot
Member
 
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184

Rep: Reputation: 34
I agree repo. Bash is not hard if you just need to do basic tasks, with the guide book I gave a link for and a couple of hours the OP could definitely knock a script together....and get a sense of well earned pride
 
  


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
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
Backup Script Help cougar97536 Linux - Newbie 8 07-09-2009 04:09 PM
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
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM

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

All times are GMT -5. The time now is 02:24 AM.

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