10/2/2018 - 2:56 AM

Rundeck migrate MySQL

Rundeck H2 to MySQL

MySQL Install

$ sudo yum localinstall
$ sudo yum-config-manager --disable mysql80-community
$ sudo yum-config-manager --enable mysql57-community
$ yum info mysql-community-server
$ sudo yum install mysql-community-server -y
$ mysqld --version
$ sudo systemctl start mysqld.service
$ sudo systemctl enable mysqld.service
$ systemctl status mysqld.service


grep 'temporary password' /var/log/mysqld.log


$ sudo mysql_secure_installation

Create database

$ mysql -u root
mysql> CREATE DATABASE rundeck;
mysql> grant ALL on rundeck.* to 'rundeckuser'@'localhost' identified by 'rundeckpassword';

Configre Rundeck

  • /etc/rundeck/
dataSource.url = jdbc:mysql://myserver/rundeck?autoReconnect=true&useSSL=false

Archive Project

  1. Project Name > Project Setting > Export Archive
  2. Choise include type
  3. Export Archive
  4. Download project_*_rdproject.jar

Backup your Rundeck data


  • /var/rundeck/projects
  • /var/lib/rundeck/data


$ aws s3 cp /var/rundeck/projects/ s3://buckets/path/projects --recursive
$ aws s3 cp /var/lib/rundeck/data/ s3://buckets/path/projects --recursive

Restart rundeck

$ sudo systemctl restart rundeckd

Import project

  1. Project Name > Project Setting > Import Archive
  2. Choise download jar file
  3. Choise Impoorted jobs

Clean Logs & execute history

#!/bin/bash -e

function join { local IFS="$1"; shift; echo "$*"; }

# keep last 30 executions for each job

cd /var/lib/rundeck/logs/rundeck

JOBS=`find . -maxdepth 3 -path "*/job/*" -type d`

for j in $JOBS ; do
  echo "Processing job $j"
  ids=`find $j -iname "*.rdlog" | sed -e "s/.*\/\([0-9]*\)\.rdlog/\1/" | sort -n -r`
  echo $ids
  declare -a JOBIDS=($ids)

  if [ ${#JOBIDS[@]} -gt $KEEP ]; then
    for job in ${JOBIDS[@]:$KEEP};do
      echo " * Deleting job: $job"
      rm -rf $j/logs/$job.*
    job_ids=$(join , ${JOBIDS[@]:$KEEP})
    wf_id=$(join , $(mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "SELECT workflow_id FROM execution WHERE id IN(${job_ids})\G" | awk '/workflow_id/{print $2}'))
    wfs_id=$(join , $(mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "SELECT workflow_step_id wfsid FROM workflow_workflow_step WHERE workflow_commands_id IN(${wf_id}) \G" | awk '/wfsid/{print $2}'))
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM log_file_storage_request WHERE execution_id IN(${job_ids})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM referenced_execution WHERE execution_id IN(${job_ids})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM execution WHERE id IN(${job_ids})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM base_report WHERE jc_exec_id IN(${job_ids})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM workflow WHERE id IN(${wf_id})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM workflow_workflow_step WHERE workflow_commands_id IN(${wf_id})"
    mysql --defaults-extra-file=/etc/rundeck/rundeck_user.cnf rundeck -e "DELETE FROM workflow_step WHERE id IN ($wfs_id)"