#304: Setting up central storage server - Rmhibbert/oe2-group-c GitHub Wiki

link to the ticket: https://rt.dataraster.com/Ticket/Display.html?id=304&results=266d64f4e0aede42d3285211cf44d408

Step by step

Connect to offsite server 20.40.64.18

Description: change the password to group-c password

Command: passwd


Setting Up SSH Keys

Description: generate an SSH key pair for each of my servers

Command: ssh-keygen -t rsa -b 4096 -C "[email protected]"


Description: Add your public key to the authorized keys each of the servers

Command: cat ~/.ssh/id_rsa.pub | ssh [email protected] "cat >> ~/.ssh/authorized_keys"


Configuring Backup Jobs

Description: For management

Command: sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/puppetlabs/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/hosts/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/default/puppetserver/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/nagios4/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /usr/lib/nagios/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/nagios/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /var/lib/prometheus/ [email protected]:/home/group-c/storage/

sudo rsync -avz -e "ssh -i ~/.ssh/id_rsa" /usr/local/bin/ [email protected]:/home/group-c/storage/


Need to check were these go next class

Backup_apps.sh

Description: Create a backup script for apps

Command: sudo nano backup-apps.sh

#!/bin/bash
TIMESTAMP=$(date +%F_%H-%M)
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /var/www/html/owncloud/ [email protected]:/home/group-c/storage/app/app-owncloud-$TIMESTAMP/
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/apache2/ [email protected]:/home/group-c/storage/app/app-apache2-$TIMESTAMP/
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/puppetlabs/ [email protected]:/home/group-c/storage/mgmt/mgmt-puppetlabs-$TIMESTAMP/

Backup_db.sh

Description: Create a backup script for db

Command: sudo nano backup-db.sh

#!/bin/bash
TIMESTAMP=$(date +%F_%H-%M)
mysqldump -u root -p'[your_password]' owncloud > /tmp/owncloud.sql
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /tmp/owncloud.sql [email protected]:/home/group-c/storage/db/db-owncloudsql-$TIMESTAMP.sql

Backup_mgmt.sh

Description: Create a backup script for mgmt

Command: sudo nano backup-mgmt.sh

#!/bin/bash
TIMESTAMP=$(date +%F_%H-%M)
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /etc/puppet/ [email protected]:/home/group-e/storage/mgmt/mgmt-puppet-$TIMESTAMP/
rsync -avz -e "ssh -i ~/.ssh/id_rsa" /opt/scripts/ [email protected]:/home/group-e/storage/mgmt/mgmt-scripts-$TIMESTAMP/

Create a init.pp inside manifest file

Description: This Puppet manifest defines a backup class that automatically configures backup jobs based on the server's role (app, db, or mgmt). It sets up the /opt/scripts directory, deploys the correct backup script, and schedules a cron job to run it four times daily at staggered intervals to balance load.

Command:

class backup (
  String $role,
) {

  # Select script based on server role
  $script_file = $role ? {
    'app'  => 'backup-app.sh',
    'db'   => 'backup-db.sh',
    'mgmt' => 'backup-mgmt.sh',
    default => fail("Unknown role: ${role}"),
  }

  # Ensure /opt/scripts directory exists
  file { '/opt/scripts':
    ensure => directory,
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  # Deploy the appropriate backup script
  file { '/opt/scripts/backup.sh':
    source => "/etc/puppetlabs/code/modules/backup/files/${script_file}",
    owner  => 'root',
    group  => 'root',
    mode   => '0755',
  }

  # Set up cron job for automated backup
  cron { 'backup-cron':
    command => '/opt/scripts/backup.sh',
    user    => 'root',
    hour    => $role ? {
      'app'  => ['0', '6', '12', '18'],
      'db'   => ['1', '7', '13', '19'],
      'mgmt' => ['2', '8', '14', '20'],
    },
    minute  => '0',
    ensure  => present,
  }

}

add the class in site.pp

Description: Assign the backup class to each node in your site.pp, specifying the correct role (app, db, or mgmt) so Puppet knows which script and schedule to apply.

Command:

class { 'backup':
  role => 'app',
}
class { 'backup':
  role => 'db',
}
class { 'backup':
  role => 'mgmt',
}

Apply the Puppet module

Description: Run the Puppet agent on each server to fetch and apply the configuration, including script deployment and cron setup.

Command: sudo puppet agent -t


Check for cron job, and run the backup script

Description: Verify that the backup cron job is installed and that the script works by executing it manually. This helps confirm that your rsync commands and database dumps are configured correctly.

Command: sudo crontab -l sudo /opt/scripts/backup.sh image image image


Here the back up file inside the offsite server image