LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 12-07-2011, 09:16 PM   #1
StaffSergeant
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 hostname.backupname.date.time.tar.gz (or bz, bz2, etc.)
-Hostname
-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 backupname.date.time 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
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Honestly, this really sounds like homework.....
 
Old 12-07-2011, 09:46 PM   #3
StaffSergeant
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
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
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
StaffSergeant
LQ Newbie
 
Registered: Nov 2011
Posts: 18

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

Code:
# 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
COMPRESSION = gzip
# E-MAIL = the e-mail address who which the daily log should be sent
E-MAIL = sergeant@unix.machine.mlb.lcl
#
# Target configuration
# BACKUP_TARGET = filesystem in which to store the backup files
BACKUP_TARGET = /backup
#TARGET_TYPE = type of filesystem used for backup_target
# local
# nfs
# smb
TARGET_TYPE = local
#TARGET_SERVER = DNS name of target server if not local
TARGET_SERVER = windows.server.net.lcl
#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:DIRECTORY:RECURSIVE: NUM_DAILY:NUM_WEEKLY:NUM_MONTHLY
# 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
home:/home:Y:2:3:1
config:/etc:Y:2:3:2

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.

Code:
#!/bin/bash
# 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 $COMPRESSION
echo $EMAIL
echo $BACKUP_TARGET
echo $TARGET_TYPE
echo $TARGET_SERVER
echo $TARGET_FS
echo $USER
echo $PASSWORD
echo $NAME
echo $DIRECTORY
echo $RECURSIVE
echo $NUM_DAILY
echo $NUM_WEEKLY
echo $NUM_MONTHLY

# Remove the tempory file created earlier
rm backup2.conf
 
Old 12-08-2011, 04:00 PM   #6
lithos
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
 
  


Reply

Tags
backup, bash, restore, scripting



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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