ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
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.
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.