Database
Howto: Install ssl with tomcat Appserver.
Five easy steps to enable SSL for tomcat application server.
1, generate Key store
keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore planetcure-in.jks
It ask few information that we would like to publish along with the SSL
==Certificate information==
Common Name : *.planetcure.in
Organization name: Xtermpro
Country/Region name: myregion
City/Locality: mycity
State/Province: mystate
2, Generate CSR
CSR it to submit to the SSL provider for digital signing Now you receive CRT file from the SSL provider, you may see the signing information in it.
keytool -certreq -alias server -file planetcure-in.csr -keystore planetcure-in.jks
3, Import CA
You may also receive a public CA from the certificate Authority, now you need to import it. This will be called as intermediate CA
keytool -import -alias intermediate -trustcacerts -file intermediateCA.cer -keystore planetcure-in.jks
4, Now this is the final stage you have to import cert file , you can see that their is another key already installed in the key store that is generated along with the keystore generation, it have to replace with the valid certificate.
keytool -import -alias server -trustcacerts -file planetcure-in.crt -keystore planetcure-in.jks
This will give the success output, now move to the configuration changes.
5, Edit the server.xml for the valid entries. Default tomcat SSL port is 8443, here I user 443 .
<Connector port="443" protocol="HTTP/1.1" maxThreads="150" scheme="https" secure="true" SSLEnabled="true" keystoreFile="${catalina.home}/conf/keystore/planetcure-in.jks" keystorePass="keystorepassword" keyAlias="server" clientAuth="false" sslProtocol="TLS"/>
that’s it, now restart the web server to make the changes effect .
script: Bash script to backup MySQL databases.
#!/bin/bash # Simple script to backup MySQL databases # # You have to enter the credintials, the scritp will make backup of all the databases # including information schema and perfomance schema as well, and store it as a gunzip format # in the backup directory. Each databases are dump as seperate files. # # This will maintain 30 days backup. If you need to extend, edit the WEIGHT as your own. # Website : https://enlook.wordpress.com , http://planetcure.info , http://xtermpro.com # Created by : Anandbabu # ################################################################################################# # Parent backup directory backup_parent_dir="/backup/" #Enter multiple email ID using space Email="email@domain.com email@domain.com" Email_Content="/tmp/Mail_db" WEIGHT=30 # 30 days # MySQL settings mysql_user="my_database_user" mysql_password='database_password' mysql_databases="Default_database" #Creating file for email [ ! -f ${Email_Content} ] && touch ${Email_Content} || :> ${Email_Content} E_mail(){ for email in ${Email} do cat ${Email_Content} | mail -s "Notification: Mysql Database Backup $@ from MyServer " ${email} -aFrom:Backup\<backup@domain.com\> done } # Read MySQL password from stdin if empty if [ -z "${mysql_password}" ]; then echo -n "Enter MySQL ${mysql_user} password: " >> ${Email_Content} read -s mysql_password echo fi # Check MySQL password echo exit | mysql --user=${mysql_user} --password=${mysql_password} -B 2>/dev/null if [ "$?" -gt 0 ]; then echo "MySQL ${mysql_user} password incorrect" >> ${Email_Content} E_mail Failed exit 1 else echo "MySQL ${mysql_user} password correct." >> ${Email_Content} fi # Create backup directory and set permissions backup_date=`date +%Y_%m_%d_%H_%M` backup_dir="${backup_parent_dir}/${backup_date}" echo "Backup directory: ${backup_dir}" >> ${Email_Content} mkdir -p "${backup_dir}" chmod 700 "${backup_dir}" # Get MySQL databases mysql_databases=`echo 'show databases' | mysql --user=${mysql_user} --password=${mysql_password} -B | sed /^Database$/d` # Backup and compress each database for database in $mysql_databases do if [[ "$database" =~ "information_schema" || "$database" =~ "performance_schema" ]] ; then additional_mysqldump_params="--skip-lock-tables" else additional_mysqldump_params="" fi echo "Creating backup of \"${database}\" database" >> ${Email_Content} mysqldump ${additional_mysqldump_params} --user=${mysql_user} --password=${mysql_password} ${database} | gzip > "${backup_dir}/${database}.sql.gz" chmod 600 "${backup_dir}/${database}.sql.gz" done ##Removing folder older than 30 days ECOUT="" echo "" >> ${Email_Content} ECOUT=`find ${backup_parent_dir} -type d -ctime +$WEIGHT` if [ -z $ECOUT ]; then echo "No more older backups to remove" >> ${Email_Content} E_mail Success exit else echo "Following older backups are removed" >> ${Email_Content} for i in $ECOUT do rm -rvf $i 1>>${Email_Content} 2>>${Email_Content} done E_mail Success exit fi
Install / Enable PHP MsSQL Extension in cPanel/WHM Server
For enabling mssql support in PHP on cpanel/WHM installed server we can’t use easyapache in this case, we need FreeTDS installed and configured which is a set of Unix/Linux libraries that implement the TDS protocol. First we will need to download and install FreeTDS, you can find more information and download link at http://www.freetds.org URL. Note the exact installation steps below :
yum install unixODBC unixODBC-devel
Step :2 freeTDS
cd /usr/local/src wget http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz tar zfvx freetds-stable.tgzcd freetds-*; ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld; make ; make install echo "--with-mssql=/usr/local/freetds" >> /var/cpanel/easy/apache/rawopts/all_php5 touch /usr/local/freetds/lib/libtds.a touch /usr/local/freetds/include/tds.h
Use this line if you get any error like no such file or directory
ln -s /usr/include/sqlext.h /usr/local/include/sqlext.h
If it it is a 64 bit server then make the following softlink
ln -s /usr/local/freetds/lib/ /usr/local/freetds/lib64
Step :3 mssql.so
Now run Easy Apache and make sure that Mysql, Mysql of the system, amd Mysqli are all selected.
/scripts/easyapache
Now you can check Mysql enabled
root@server [~]# php --info |grep "mssql" MSSQL Support => enabled
How to Copy backup a MySQL Database
Posted on Updated on
The mysqldump Command
The mysqldump command creates a text version of the database. Specifically, it creates a list of SQL statements which can be used to restore/recreate the original database.
# mysqldump -uusername -ppasswd dbname > backupfile.sql
or
# mysqldump -B openfire > /home/db.sql
or
# mysqldump –all-databases -r dbdump.sql -uroot-p
[username] Your database username
[passwd] The password for your database
[dbname] The name of your database
[backupfile.sql] The filename for your database backup
You can dump a table, a database, or all databases.
To dump all MySQL databases on the system, use the –all-databases shortcut:
# mysqldump -u root -p –all-databases > backupfile.sql
Restoring a MySQL Database
Use this method to rebuild a database from scratch
# mysql -u username -p passwd database_to_restore < /path/to/file.sql
Use this method to import into an existing database (i.e. to restore a database that already exists)
# mysqlimport -u sadmin -p pass21 db_name DBback.sql
or
# mysqlimport options database textfile
or
mysql>use dbname; <select the existing DB >
mysql>source /home/db.sql; <restore backup to the db>
Share this:
This entry was posted in Databases, Mysql Comments and tagged Database.