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.
|
|
07-26-2007, 12:10 AM
|
#1
|
LQ Newbie
Registered: Jan 2007
Posts: 2
Rep:
|
how write a script
Hi, im new to linux and my boss has given me a project to write a script for takeing a backup every day time.
|
|
|
07-26-2007, 12:57 AM
|
#2
|
Member
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Rep:
|
Well, if you don't know how to write a script then maybe it's time to look for a new job
The short answer is: A script is simply a list of commands in a text file that are executed one after the other.
The only condition is that the file have executable permissions.
Take a look at the Advanced Bash-Scripting Guide. There is tons of info on there. Also open up your favourite IRC client and go to #bash on irc.freenode.net
|
|
|
07-26-2007, 02:53 AM
|
#3
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
This isn't really the right forum for a question. You should have posted it in the newbies section, so don't be surprised if a moderator moves it there.
You didn't indicate which distro you are using and what hardware is used to make backups.
Normally the tar command is used to produce the backups and often the find command is used to locate files more recent than the latest backup. If you want the backup script to be run automatically, then you will probably want to write a cron script.
If you use access control lists, then read the documentation for your version of the tar command. You may need to use the star command instead. It is similar to tar but can also backup the acl lists associated with the file. ( see the man page for getfacl and setfacl. ) If setfacl and getfacl aren't installed then you don't use them.
If you will be backing up to DVD, look into dar and kdar. Dar stands for disk archiver. It writes backups into slices which can be CDROM or DVD size segments. The kdar program is a graphical interface to dar. It allows you to easily configure what you want to be backed up, and the type of backup. For example, once a month, you might perform a total backup, and then have another job to perform incremental backups. Using kdar, you can export the job as a bash script and use that script as your cron executed script.
Another advantage of using dar or kdar is that it tracks files that have been deleted since the last backup. So suppose that an emergency happens and you need to restore the system, starting from the initial full backup, and then each incremental backup. If you deleted a file between the 2nd & 3rd backup, restoring from the 3rd backup, dar will delete that file. This way you don't end up with a bunch of obsolete file orphans that you don't want.
|
|
|
07-26-2007, 03:22 AM
|
#4
|
Member
Registered: Nov 2005
Location: Turkey
Distribution: Suse
Posts: 104
Rep:
|
May be you can call rsync or you can write perl instead of bash script (i need to tell other solutions)
Thnx
|
|
|
07-26-2007, 07:17 AM
|
#5
|
Member
Registered: May 2007
Posts: 89
Rep:
|
Re:...
Don't worry...shell scripting is easy to learn...
First, you need to know from your boss the following..
1. Whether you want to take the back of only those files created or modified on that day or you want to take the full system file backup like compressing the entire files under / directory..??
2. Read the book Begining linux programming 3 rd edition...i think e-book is available on the net. There try the shell scripting chapter..
3. Then, you make a complete study on the date command, tar command and also how to start your script at the startup.
So, the concept is, you need to start your script at the startup, check the date and time continuosly, when the desired time arrives, run the script files automatically which backup the system files...
Hope you will do well....
|
|
|
07-26-2007, 08:16 AM
|
#6
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
Quote:
Originally Posted by saif
Hi, im new to linux and my boss has given me a project to write a script for takeing a backup every day time.
|
Does your boss believe that you already know how to do this
Add to the list of reading material: Bash Guide for Beginners, by Machtelt Garrels (at tldp.org)
|
|
|
07-27-2007, 02:56 AM
|
#7
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,415
|
|
|
|
07-27-2007, 06:07 AM
|
#8
|
LQ Newbie
Registered: Jan 2007
Posts: 2
Original Poster
Rep:
|
Hi,
thx to all who replayed to me.
|
|
|
07-27-2007, 01:31 PM
|
#9
|
Member
Registered: Sep 2006
Location: Canada, Alberta
Distribution: RHEL 4 and up, CentOS 5.x, Fedora Core 5 and up, Ubuntu 8 and up
Posts: 251
Rep:
|
Hmm, well funny story is I never touched Linux and my boss expected the same. I was lucky though he taught me everything and I "self taught" my self as I went a long. Scripting is fairly easy but can be tough to get into because you don't know where to start.....
1) you will need to go through some basic bash and shell scripting tutorial as mentioned by the others
2) is the backup script for a linux box, windows box or mac? i would assume linux.
3) like the other LQ memeber said, what is it you want to backup? for exmaple if you have 5 users on the linux system, do you want to backup all 5 users or just 2? i would hope all 5. next thing is what do you want to backup from each user..... once you know the criteria for your backup you should be good to go for writing the script.
4) to write a script first write out your plan (for beginners, its called pseudo code)
so lets say i want to copy files from user johnny on my linux box to the backup directory which you will need to create (so you have to make a directory called /home/backup. now i want to back up johnnys documents which are stored in /home/johnny/documents. so you know your first line of code has to copy the directory /home/johnny/documents/*. the star is a wild card so any and all files will copy over to the backup directory. once you have copied the files over then you should compress them, not once but twice, use a tarball and then gzip. once they are compressed you can delete the old backup directory /home/backup/johnny/documents thus removing the un-needed files which have been compressed in to a tar.gz file to save space (if you ever need to go to the backup you just uncompress the tar.gz file which will recreate johnny/documents). now to be safe i would take a copy of the compressed backup file and copy it to another machine, preferable another linux box. if you don't have one then maybe use an external USB drive or you can map to a windows box (you would have to create a share on the windows box you want to backup to).
you should create a log file to so that you can see your backup steps, can help you with that as well - once your there.
you will need to maintain and control your backup files you will want to keep a cycle of them to prevent them from taking up a tone of space. lets say 2 weeks worth, 14 days. you will need to create a script for this to - more advanced but i can explain once we get the first script done. basically you create an automated script to remove files older than 14 days thus keeping 14 days worth of backups on your server.
now that you have the plan you can write the script
5) writing the script - once you get here i can help
Now what the other guys say about you getting a new job well that might be true, but why the heck would your boss ask you to do this if he knows you cant? i dont think we (LQ memebers) are getting the full story....
GOOD LUCK
Last edited by bskrakes; 07-27-2007 at 01:36 PM.
|
|
|
All times are GMT -5. The time now is 02:12 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
|
|