bash scripting help
Posted by: sqwaw
Posted on: 2005-07-11 17:14:00
I'm making a program to backup the forums, only I don't know enough bash programming knowledge to do this... This is my script so far, it's only got about 10 errors total, so please help. Thanks.
#!/bin/sh
###################
# Start of Config #
###################
pathtobackup = "/home/sqwaw/backups"; # path for backups
foldername = `date`; # name for backup folder date and time stamped
dbuname = "titan"; # mysql username
dbpwd = "MY-PASSWORD"; # mysql password
dbname = "titandb"; # mysql db name
dbhost = "db.forum.sqwaw.com"; # mysql hostname
ftpswitch = 1; # switch ftp on/off # 1=on 0=off
ftphost = "sqwaw.com"; # ftp server hostname
ftpuname = "sqwaw"; # ftp username
ftppwd = "MYPASSWORD"; # ftp pass
ftppath = "/"; # ftp path
###################
# End of Config #
###################
# Anything you change below here is done at your own risk!
# Begin
echo Starting SQL backup!
# Move us to the backup folder, or exit.
if
cd $pathtobackup
# Defined correctly in configuration... hopefully.
then
echo The backup folder WAS CD successfully!
# Changed dir to backup folder without complication.
else
echo The folder backups are to be stored in could NOT be successfully mounted!
exit 0
# Couldn't mount backup folder, exit.
fi
# Sorted folders in backup dir
echo Creating sorted folder in $pathtobackup
if
mkdir $foldername
then
echo Sorted folder created successfully!
chmod 777 $foldername
# Make the dir publically accessible?
fi
# Creating SQL Dump
echo Dumping the current SQL database
path=$($pathtobackup/$foldername/$dbname.sql)
cd $foldername
if
# Dump file to $pathtobackup using provided $dbuname, $dbhost,, $dbpwd, and $dbname
mysqldump --user=$dbuname
--host $dbhost
--password=$dbpwd --flush-logs
--lock-tables $dbname >
$dbname.sql;
then
# echo message
echo The dump was created successfully!
else
# echo message
echo An error has occured, dump not completed!
exit 0
fi
# Gzipping the SQL dump
echo Gzipping of the SQL database commencing...
cd $foldername
# Go to the sorted dump folder
tar -cf $dbname.tar $dbname.sql
# Compress the SQL Dump -> .tar
if
gzip -9 $DB.tar
then
echo $dbname.tar.gz sucessfully created!
else
echo Tarball was not created or Gzipped successfully!
fi
# FTP the backup to a remote FTP server
if
$ftpswitch -eq 1
then
# Login to the FTP server, outputting the screen to ftplog
ftp -n $ftphost <<ftplog
# specify a user
user $ftpuname
# provide pass
$ftppwd
# navigate to folder store and put files
cd $ftppath
mkdir $foldername
cd $foldername
put $dbname.tar.gz.enc
put $dbname.tar.gz
quit
# quit the ftp
fi
echo ftplog
echo Backup worked... Hopefully!
exit 1
# return result