• Crontab Scripting - Lexical Error

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #30805  by alexwgordon
 
Hi Guys,

So I'm having issues right now working out a backup system for my OpenKM setup. Right now I'm using this MySQL script
http://wiki.openkm.com/index.php/Backup_scripts

I'm running OpenKM Version: 6.3.1-DEV (build: 8178) on a Windows Server running Cygwin.

So basically I've tested the script and it works fine in Cygwin, but when I go to run it in the crontab it says it executes but doesn't output anything; so I ran the file in Admin > Scripting and got this error:

Sourced file: inline evaluation of: ``#!/bin/bash # ## BEGIN CONFIG ## MYSQL_PASS="password" DATABASE_EXP="/backup/lo. . . '' Token Parsing Error: Lexical error at line 2, column 2. Encountered: "\r" (13), after : "#":
Code: Select all
#!/bin/bash
#
## BEGIN CONFIG ##
MYSQL_PASS="password"
DATABASE_EXP="/backup/location"
## END CONFIG ##
 
rm -rf $DATABASE_EXP
mkdir -p $DATABASE_EXP
 
# Backup de MySQL
if [ -n "$MYSQL_PASS" ]; then
  MYSQL_DBS=$(mysqlshow -h localhost -u root -p$MYSQL_PASS | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) { print $2 }');
 
  for DB in $MYSQL_DBS; do
    if [[ $DB != "mysql" && $DB != "test" && $DB != "information_schema" && $DB != "performance_schema" ]]; then
      echo "* Backuping MySQL data from $DB..."
      mysqldump -h localhost -u root -p$MYSQL_PASS $DB > $DATABASE_EXP/mysql_$DB.sql
    fi
  done
fi
I did find that this is the exact same thing that was found in this x-post but had no solution.
http://forum.openkm.com/viewtopic.php?f=5&t=12416

So any and all advice would be so greatly appreciated! Thank you so much in advance! Happy New Years everyone :D
 #30807  by jllort
 
The backup script you paste here is only for linux in crontab you should use bean shell scripting or java jar file ( I suggest second option ). If you're on windows ( seems your case ) you should use windows utilities for doing backup
 #30812  by alexwgordon
 
Hi Jllort,

Ah I figured since I had Cygwin/rsync installed this could work out, but seems that that's not the case? I'm new to Windows server admin stuff, is there any documentation on a preferred method of backing up the repo/settings and everything for a Windows Server? Also can it do incremental backups?

Thanks jllort, always appreciate the speedy replies and help :D
 #30816  by jllort
 
There's no suggestion on how doing backups on Windows. Only I can tell you what must doing backup
1- folder repository/datastore ( file system ). althought my suggestion is entire openkm folder ( tomcat application is really small )
2- database backup ( I suggest configure mysql -> then execute daily mysqldump and also copy with process one, file system files).

The best option to know if you're doing things correctly is restore in other computer
 #30880  by alexwgordon
 
Hi jllort,

Okay so if I follow you right I think I came up with a nice little ssh/rsync protocol that I can run from a remote unix computer (Mac) to backup (1) the tomcat folder via rsync/ssh and (2) the MySQL. It'd be nice if it ran through the crontab, but this works perfectly fine for me to run manually with minimal effort and incremental backups.

I'll share my scripts here in case anyone is interested! Keep in mind this is running scripts from a Mac OS X remote client on a Windows Server OpenKM installation running Cygwin (which I don't know if that's even necessary now that I'm running rsync from the Mac). But here's my procedure anyway :)

I ended up writing a script to call another script to make things easier:
Started by making an alias to quickly call up the scripts
Code: Select all
alias okmb='sh /Users/[username]/Desktop/backup.sh'
Then created 2 scripts (probably didn't have to but found this way to be trouble-free:

backup.sh
Code: Select all
ssh -t remoteuser@remoteIP 'bash -s' < /Users/[username]/Desktop/backup1.sh
echo "* Backing up MySQL to remote external drive!"
rsync -avzP -e ssh remoteuser@remoteIP:/cygdrive/d/OpenKM/backup/test3/MySQL /directory/on/local/machine
echo "* Backing up Tomcat folder to remote external drive!"
rsync -avzP -e ssh remoteuser@remoteIP:/cygdrive/c/openkm-6.3.0-community/tomcat /directory/on/local/machine
backup1.sh
Code: Select all
#!/bin/bash
#
## BEGIN CONFIG ##
MYSQL_PASS="password"
SERVERFOLDER="/path/to/MySQL/backup/destination"
## END CONFIG ##

rm -rf $SERVERFOLDER
mkdir -p $SERVERFOLDER

# Backup of MySQL
if [ -n "$MYSQL_PASS" ]; then
	MYSQL_DBS=$(mysqlshow -h localhost -u root -p$MYSQL_PASS | awk '(NR > 2) && (/[a-zA-Z0-9]+[ ]+[|]/) { print $2 }');
	for DB in $MYSQL_DBS; do
		if [[ $DB != "mysql" && $DB != "test" && $DB != "information_schema" && $DB != "performance_schema" ]]; then
			echo "* Backing up MySQL data to backup folder from $DB..."
			mysqldump -h localhost -u root -p$MYSQL_PASS $DB > $SERVERFOLDER/mysql_$DB.sql
		fi
	done
fi
Hopefully that helps someone else. Also keep in mind you'll have to setup your passwordless SSH on the server; I followed this http://users.cecs.anu.edu.au/~xzhang/pu ... indows.htm
 #31062  by pavila
 
It's a bit confusing but I'll try to explain:

* In OpenKM sometimes we call scripts to the code which is ejecuted from Administration > Utilities > Scripting and Administration > Crontab. This code is BeanShell (something like interpreted Java). You can't execute Bash scripts here.

* Backup scripts are written in Bash for Linux. You can't execute BeanShell scripts here.

Also, in OpenKM we have Administration > Crontab which are (beanshell) scripts that are executed every a certain period of time. This is very like to Linux crontan which can execute Bash scripts at certain periods of time.

I hope this help you.

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.