You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by ilya <il...@gmail.com> on 2015/03/17 18:10:36 UTC
CloudStack DB Backup Script - Fetching mysql details from db.properties
It would be ideal if we can make this or similar script as part of
cloudstack upgrade procedure i.e. create backups before start!
CloudStack DB Backup Script - Fetching mysql details from db.properties
#!/bin/bash
DBNAMES="cloud cloud_usage cloudbridge"
DATE=$(date +%m%d%y-%H%M%S)
DBPASS=$(java -classpath
/usr/share/cloudstack-common/lib/jasypt-1.9.0.jar
org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="$(cat
/etc/cloudstack/management/db.properties | grep db.cloud.password | awk
-F'(' '{print $2}' | sed 's/)//g')" password="$(cat
/etc/cloudstack/management/key)" | grep -A2 OUTPUT | tail -1)
#Assuming that cloud user can access all 3 dbs
DBHOST=$(cat /etc/cloudstack/management/db.properties | grep
db.cloud.host | awk -F'=' '{print $2}' | tail -1 )
DBUSER=$(cat /etc/cloudstack/management/db.properties | grep
db.cloud.username | awk -F'=' '{print $2}')
DB=$(cat /etc/cloudstack/management/db.properties | grep db.cloud.name |
awk -F'=' '{print $2}')
DBPORT=$(cat /etc/cloudstack/management/db.properties | grep
db.cloud.port | awk -F'=' '{print $2}')
#echo $DBPASS $DBHOST $DBUSER $DB $DBPORT
for DB in $DBNAMES
do
printf "Backing up DB $DB, please wait .... "
mysqldump -h $DBHOST -u $DBUSER -P $DBPORT -p$DBPASS
$DB >$DB.$(hostname -s).$DATE.sql && echo "done" || echo "error!"
done
echo -e "\nCompressing all files into single tar.gz -
all-cloud-dbs.$(hostname -s).$DATE.sql.tgz file ..."
tar -zcvf all-cloud-dbs.$(hostname -s).$DATE.sql.tgz *$(hostname
-s).$DATE.sql && echo -e "done\n" || echo -e "error!\n"
printf "Cleaning up .... "
rm -rf *$(hostname -s).$DATE.sql && echo -e "done\n" || echo "error!\n"
Re: CloudStack DB Backup Script - Fetching mysql details from db.properties
Posted by Pierre-Luc Dion <pd...@cloudops.com>.
That's nice! it would be triggered only when upgrade of DB occur while
upgrading a release, right? not everytime a cloudstack-management server is
restarted?
Where would you dump db files?
On Tue, Mar 17, 2015 at 1:10 PM, ilya <il...@gmail.com> wrote:
> It would be ideal if we can make this or similar script as part of
> cloudstack upgrade procedure i.e. create backups before start!
>
>
> CloudStack DB Backup Script - Fetching mysql details from db.properties
>
>
>
> #!/bin/bash
> DBNAMES="cloud cloud_usage cloudbridge"
> DATE=$(date +%m%d%y-%H%M%S)
> DBPASS=$(java -classpath /usr/share/cloudstack-common/lib/jasypt-1.9.0.jar
> org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="$(cat
> /etc/cloudstack/management/db.properties | grep db.cloud.password | awk
> -F'(' '{print $2}' | sed 's/)//g')" password="$(cat
> /etc/cloudstack/management/key)" | grep -A2 OUTPUT | tail -1)
> #Assuming that cloud user can access all 3 dbs
> DBHOST=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.host | awk -F'=' '{print $2}' | tail -1 )
> DBUSER=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.username | awk -F'=' '{print $2}')
> DB=$(cat /etc/cloudstack/management/db.properties | grep db.cloud.name |
> awk -F'=' '{print $2}')
> DBPORT=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.port | awk -F'=' '{print $2}')
> #echo $DBPASS $DBHOST $DBUSER $DB $DBPORT
> for DB in $DBNAMES
> do
> printf "Backing up DB $DB, please wait .... "
> mysqldump -h $DBHOST -u $DBUSER -P $DBPORT -p$DBPASS $DB
> >$DB.$(hostname -s).$DATE.sql && echo "done" || echo "error!"
> done
> echo -e "\nCompressing all files into single tar.gz -
> all-cloud-dbs.$(hostname -s).$DATE.sql.tgz file ..."
> tar -zcvf all-cloud-dbs.$(hostname -s).$DATE.sql.tgz *$(hostname
> -s).$DATE.sql && echo -e "done\n" || echo -e "error!\n"
> printf "Cleaning up .... "
> rm -rf *$(hostname -s).$DATE.sql && echo -e "done\n" || echo "error!\n"
>
Re: CloudStack DB Backup Script - Fetching mysql details from db.properties
Posted by Pierre-Luc Dion <pd...@cloudops.com>.
That's nice! it would be triggered only when upgrade of DB occur while
upgrading a release, right? not everytime a cloudstack-management server is
restarted?
Where would you dump db files?
On Tue, Mar 17, 2015 at 1:10 PM, ilya <il...@gmail.com> wrote:
> It would be ideal if we can make this or similar script as part of
> cloudstack upgrade procedure i.e. create backups before start!
>
>
> CloudStack DB Backup Script - Fetching mysql details from db.properties
>
>
>
> #!/bin/bash
> DBNAMES="cloud cloud_usage cloudbridge"
> DATE=$(date +%m%d%y-%H%M%S)
> DBPASS=$(java -classpath /usr/share/cloudstack-common/lib/jasypt-1.9.0.jar
> org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="$(cat
> /etc/cloudstack/management/db.properties | grep db.cloud.password | awk
> -F'(' '{print $2}' | sed 's/)//g')" password="$(cat
> /etc/cloudstack/management/key)" | grep -A2 OUTPUT | tail -1)
> #Assuming that cloud user can access all 3 dbs
> DBHOST=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.host | awk -F'=' '{print $2}' | tail -1 )
> DBUSER=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.username | awk -F'=' '{print $2}')
> DB=$(cat /etc/cloudstack/management/db.properties | grep db.cloud.name |
> awk -F'=' '{print $2}')
> DBPORT=$(cat /etc/cloudstack/management/db.properties | grep
> db.cloud.port | awk -F'=' '{print $2}')
> #echo $DBPASS $DBHOST $DBUSER $DB $DBPORT
> for DB in $DBNAMES
> do
> printf "Backing up DB $DB, please wait .... "
> mysqldump -h $DBHOST -u $DBUSER -P $DBPORT -p$DBPASS $DB
> >$DB.$(hostname -s).$DATE.sql && echo "done" || echo "error!"
> done
> echo -e "\nCompressing all files into single tar.gz -
> all-cloud-dbs.$(hostname -s).$DATE.sql.tgz file ..."
> tar -zcvf all-cloud-dbs.$(hostname -s).$DATE.sql.tgz *$(hostname
> -s).$DATE.sql && echo -e "done\n" || echo -e "error!\n"
> printf "Cleaning up .... "
> rm -rf *$(hostname -s).$DATE.sql && echo -e "done\n" || echo "error!\n"
>