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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
12-19-2009, 10:19 AM
|
#1
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Rep:
|
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
|
|
|
12-19-2009, 10:25 AM
|
#2
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
Quote:
Originally Posted by marydoll
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 
|
|
|
12-19-2009, 10:38 AM
|
#3
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
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
|
|
|
12-19-2009, 10:39 AM
|
#4
|
Senior Member
Registered: Jul 2008
Location: /dev/null
Posts: 1,173
Rep: 
|
Both backup and restore operations can be done using "cp".
Regards
|
|
|
12-19-2009, 10:56 AM
|
#5
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
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.
|
|
|
12-19-2009, 11:27 AM
|
#6
|
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
|
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.
|
|
|
12-19-2009, 11:53 AM
|
#7
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
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)
|
|
|
12-19-2009, 11:55 AM
|
#8
|
Member
Registered: Dec 2009
Posts: 37
Rep:
|
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.
|
|
|
12-19-2009, 12:02 PM
|
#9
|
Member
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184
Rep:
|
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.
|
|
|
12-19-2009, 12:05 PM
|
#10
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
cant use sofwtware to try ubuntu iso would not load (pc would not read disk) using college's vm to test, thanks for suggestion.
|
|
|
12-19-2009, 12:06 PM
|
#11
|
Member
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184
Rep:
|
To run that script you posted you need to run it with -n or -f to function properly.
|
|
|
12-19-2009, 12:13 PM
|
#12
|
Member
Registered: May 2007
Location: Bulgaria
Distribution: Slackware, SCO Unix
Posts: 62
Rep:
|
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>
|
|
|
12-19-2009, 12:14 PM
|
#13
|
LQ Newbie
Registered: Dec 2009
Posts: 12
Original Poster
Rep:
|
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
|
|
|
|
12-19-2009, 12:46 PM
|
#14
|
LQ 5k Club
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529
|
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.
|
|
|
12-19-2009, 02:07 PM
|
#15
|
Member
Registered: Mar 2002
Location: I can see you from here.
Distribution: Gentoo 1.3b
Posts: 184
Rep:
|
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 
|
|
|
All times are GMT -5. The time now is 01:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|