Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 12-07-2011, 09:16 PM   #1
LQ Newbie
Registered: Nov 2011
Posts: 18

Rep: Reputation: Disabled
backup/restore scripts

Looking to make a backup script and a simple restore script.

I want to store the backup target from a file I pull from in a tar archeiver - so compress the tar file using a compression utility which was specified in the config file and put into a variable.

-Also want backups to be named (or bz, bz2, etc.)
-backupname (matches the backupname in the config file)
-date (date in YYYY-MM-DD format)
-time (time in HH:MM 24 hour format)
I think you can find switches to the date command that would be eaiest.
Example: sergeat.home.2011-12-06.22:14.tar.gz

The backups should be placed in the target directory as found in the config file as a variable ( i have already wrote stuff to pull that out) But the script needs to create any non-existent directories

- the script needs to create a new log file in /var/log/backup each time the script executes. The file should be named with parameters same as the backup file name. The log should contain the date and time as well as a list of files backed up (this could be done using the ls with flags to generate the list of files)

Restore part:

Write a restore script that restores the contents of a backup to the system
o The restore script should be called from the machine to be restored with the name of the backup file as a parameter
o The script should ask the user to verify the operation then restore the files
Overwriting any existing files

Any help would be awesome bits and peices blessful as well. I am just trying to hammer away at this and causing more harm than good.
Old 12-07-2011, 09:34 PM   #2
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
Honestly, this really sounds like homework.....
Old 12-07-2011, 09:46 PM   #3
LQ Newbie
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
That I do not deny. Just looking for help.
Old 12-08-2011, 01:56 AM   #4
Registered: Apr 2005
Posts: 5,807

Rep: Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996Reputation: 996
So then please post what you have so far, then ask questions. We will not do your homework for you.
1 members found this post helpful.
Old 12-08-2011, 05:18 AM   #5
LQ Newbie
Registered: Nov 2011
Posts: 18

Original Poster
Rep: Reputation: Disabled
This is a test file I made from an earlier program.

# Backup script configuration file
# last modified 112109 by P.T. Rawles
# General configuration
# COMPRESSION = compression program
# value should be the command used to compress the tar file
# default is gzip
# E-MAIL = the e-mail address who which the daily log should be sent
# Target configuration
# BACKUP_TARGET = filesystem in which to store the backup files
#TARGET_TYPE = type of filesystem used for backup_target
# local
# nfs
# smb
#TARGET_SERVER = DNS name of target server if not local
#TARGET_FS = filesystem/share/export on the target server that will be mounted to backup_target
TARGET_FS = /backups
# USER = username for SMB target
USER = backup
# PASSWORD = password for user
PASSWORD = user_pass
# # Backup entries
# colon separated entries for each directory to backup in the format:
# NAME – the name of this directory entry
# DIRECTORY – the directory to backup
# RECURSIVE – a Boolean Y/N whether to backup subdirectories
# NUM_DAILY – the number of daily copies to keep
# NUM_WEEKLY – the number of weekly copies to keep
# NUM_MONTHLY – the number of monthly copies to keep

Then this is a backup script I have been working on. It pulls from from the test file (backup.conf) ^ and makes variables...this is where i got stuck.

# Backup Script

# Read the backup.conf file, export anything that is not commented
# to a temp file  called  "backup2.conf".
cat backup.conf | grep -v '#' > backup2.conf

# Set variables to their desired information based on their values
COMPRESSION=$(expr "$(grep 'COMPRESSION' backup2.conf)" : '.*= \(.*\)')
EMAIL=$(expr "$(grep 'E-MAIL' backup2.conf)" : '.*= \(.*\)')
BACKUP_TARGET=$(expr "$(grep 'BACKUP_TARGET' backup2.conf)" : '.*= \(.*\)')
TARGET_TYPE=$(expr "$(grep 'TARGET_TYPE' backup2.conf)" : '.*= \(.*\)')
TARGET_SERVER=$(expr "$(grep 'TARGET_SERVER' backup2.conf)" : '.*= \(.*\)')
TARGET_FS=$(expr "$(grep 'TARGET_FS' backup2.conf)" : '.*= \(.*\)')
USER=$(expr "$(grep 'USER' backup2.conf)" : '.*= \(.*\)')
PASSWORD=$(expr "$(grep 'PASSWORD' backup2.conf)" : '.*= \(.*\)')

# For the back up requested by the user, find each of the 6 fields.
NAME=$(cat backup2.conf | grep $1 | cut -d: -f1)
DIRECTORY=$(cat backup2.conf | grep $1 | cut -d: -f2)
RECURSIVE=$(cat backup2.conf | grep $1 | cut -d: -f3)
NUM_DAILY=$(cat backup2.conf | grep $1 | cut -d: -f4)
NUM_WEEKLY=$(cat backup2.conf | grep $1 | cut -d: -f5)
NUM_MONTHLY=$(cat backup2.conf | grep $1 | cut -d: -f6)

# Echo all variables and send to stdout
echo $EMAIL
echo $USER
echo $NAME

# Remove the tempory file created earlier
rm backup2.conf
Old 12-08-2011, 04:00 PM   #6
Senior Member
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
I don't know what is wrong with your variables, but backing up script you can look at here

good luck


backup, bash, restore, scripting

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
[SOLVED] Mysql Backup & Restore scripts ramecare Linux - Server 3 04-11-2011 05:29 AM
Need a fresh pair of eyes to review my backup+restore scripts BassKozz Linux - Newbie 6 06-01-2009 04:51 AM
cannot restore backup jon23d Linux - General 2 11-02-2006 05:24 PM
how to restore the startup scripts after removal kushalkoolwal Debian 6 05-10-2006 01:06 PM
RH 7.3 Backup and Restore MrJoshua Linux - General 1 06-18-2003 11:39 AM

All times are GMT -5. The time now is 10:01 PM.

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 @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration