-   Programming (
-   -   backup/restore scripts (

StaffSergeant 12-07-2011 10:16 PM

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.

corp769 12-07-2011 10:34 PM

Honestly, this really sounds like homework.....

StaffSergeant 12-07-2011 10:46 PM

That I do not deny. Just looking for help.

corp769 12-08-2011 02:56 AM

So then please post what you have so far, then ask questions. We will not do your homework for you.

StaffSergeant 12-08-2011 06:18 AM

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

lithos 12-08-2011 05:00 PM

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

good luck

All times are GMT -5. The time now is 09:52 AM.