Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-26-2007, 12:10 AM   #1
LQ Newbie
Registered: Jan 2007
Posts: 2

Rep: Reputation: 0
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.
Old 07-26-2007, 12:57 AM   #2
Registered: Jul 2005
Location: England, UK
Distribution: Ubuntu 8.04 Server, Kubuntu 12.04
Posts: 698
Blog Entries: 1

Rep: Reputation: 31
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
Old 07-26-2007, 02:53 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
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.
Old 07-26-2007, 03:22 AM   #4
Registered: Nov 2005
Location: Turkey
Distribution: Suse
Posts: 104

Rep: Reputation: 16
May be you can call rsync or you can write perl instead of bash script (i need to tell other solutions)

Old 07-26-2007, 07:17 AM   #5
Registered: May 2007
Posts: 89

Rep: Reputation: 15

Don't 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....
Old 07-26-2007, 08:16 AM   #6
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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
Old 07-27-2007, 02:56 AM   #7
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,417

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
another good Linux tutorial
Old 07-27-2007, 06:07 AM   #8
LQ Newbie
Registered: Jan 2007
Posts: 2

Original Poster
Rep: Reputation: 0
thx to all who replayed to me.
Old 07-27-2007, 01:31 PM   #9
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: Reputation: 32
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....


Last edited by bskrakes; 07-27-2007 at 01:36 PM.


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
script to write to a cd nasirdaudahmad Linux - Hardware 3 01-24-2007 12:45 AM
wanna write a script djflix Linux - Newbie 4 09-07-2005 12:54 PM
How to write a Script Blake Linux - Software 6 07-18-2004 12:41 PM
how to write this script? MeganageM Linux - Newbie 1 03-10-2004 06:01 PM
Help with a script I need to write... cmfarley19 Programming 9 12-06-2003 01:10 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:35 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