- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Backup script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 03:22 AM
тАО06-13-2007 03:22 AM
Im logged as a root, the script is in my home location /home/myuser/myscript
I'm getting this output:
: command not found
: command not found
: command not found
: command not found
'sqlback: line 24: syntax error near unexpected token `do
'sqlback: line 24: ` sed -e "s/\/var\/lib\/mysql\///"`; do
when I'm trying to run this script on my linux machine:
#!/bin/sh
PATH="/bin:/usr/bin:/usr/sbin:/sbin:/bin/bin:/usr/local/sbin:/usr/local/bin"
data=`date +%Y-%m-%d`
kat=/home/peterkirklewski/msqlbackup #backup dir
tempdir=/tmp/mysqlback
if [ -e $kat ]; then
exit
else
mkdir $kat
fi
PASS="Zxxxxx"
rm -rf /tmp/mysqlback
mkdir /tmp/mysqlback
for var in `find /var/lib/mysql/ -type d | \
sed -e "s/\/var\/lib\/mysql\///"`; do
echo $var
mysqldump -u root --password=$PASS --opt --all $var > $kat/$var.sql done
How to get rid of this problem ?
Cheers
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 03:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 03:37 AM
тАО06-13-2007 03:37 AM
Re: Backup script
One problem is that you appear to have too many "/" and/or no ";" or newline before the 'done':
...
for var in `find /var/lib/mysql/ -type d | \
sed -e "s/\/var\/lib\/mysql\//"`; do
echo $var
done
Regards!
...JRF...
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 03:51 AM
тАО06-13-2007 03:51 AM
Re: Backup script
set -x
as the first line in your script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 04:51 AM
тАО06-13-2007 04:51 AM
Re: Backup script
> mkdir /tmp/mysqlback
There's no test to see if mkdir was successful. If it fails, your script goes on assuming that the directory does indeed exist. Check the return code:
mkdir /tmp/mysqlback
ERR=$?
[ $ERR -ne 0 ] && echo "mkdir failed error $ERR" && exit 1
Now this won't fix your problem, but it is a minimum when you are writing production script. Always test that each task is successful (or assume that everything fails until proven successful)
> for var in `find /var/lib/mysql/ -type d | \
> sed -e "s/\/var\/lib\/mysql\///"`; do
> echo $var
> mysqldump -u root --password=$PASS --opt --all $var > $kat/$var.sql done
For reliability, it is important to test each step before moving on. It appears that you are using sed to strip off the leading /var/lib/mysql path and keep what is left. So if that directory has no directories in it, the command fails unexpectedly. The sed expression will return subdirectories too as in:
echo "/var/lib/mysql/a/b/c"| sed -e "s/\/var\/lib\/mysql\///"
a/b/c
This may also be a failure that must be tested.
I would rewrite this so you can see each step:
MYFIND=$(find /var/lib/mysql -type d)
[ "$VAR" = "" ] && echo "\nNo dirs found\n" && exit 2
for VAR in "$MYFIND"
do
DIR=$(echo $VAR | ed -e "s/\/var\/lib\/mysql\///")
[ "$DIR" = "" ] && echo "\nNull DIR value" && exit 3
echo $DIR
mysqldump -u root --password=$PASS --opt --all $DIR > $kat/$DIR.sql
ERR=$?
[ $ERR -ne 0 ] && echo "\nmysqldump failed on DIR=$DIR\n" && exit 4
done
Now you can see each step when you run it with set -x at the top of the script.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 04:54 AM
тАО06-13-2007 04:54 AM
Re: Backup script
DIR=$(echo $VAR | sed -e "s/\/var\/lib\/mysql\///")
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2007 05:35 AM
тАО06-13-2007 05:35 AM
Re: Backup script
- There is no need to diddle with backslash-escapes in the sed, just don't use '/' as delimiter.
- If no variables are involved in search/replace - strings I recommend to use single quotes, if needed.
- To overcome the directory-hierarchie-problem, drop the '/' in your result string.
So try:
..
for var in $(find /var/lib/mysql/ -type d |
sed -e s,/var/lib/mysql/,, -e s,/,-,,)
do
...
mfG Peter