Skip to content

Commit

Permalink
Use a crontab job to keep the external data up to date
Browse files Browse the repository at this point in the history
  • Loading branch information
cailafinn committed Sep 24, 2024
1 parent c6e51fa commit 6972988
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Linux/external-data-mirror/ansible/roles/mirror/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@
state: directory
mode: '0755'

- name: Check if machine has SSH access to the main data store.
ansible.builtin.command: ssh {{ main_server_user }}@{{ main_server_ip }} 'echo success'
register: connected

- name: Exchange SSH keys with linode so we can access the data.
import_tasks: exchange-keys.yml
when: connected.stdout != "success"

- name: Mirror the external data from the main server in a volume (this may take a while).
ansible.builtin.command: "rsync -az --perms -o -g {{ main_server_ip }}:/srv/{{ main_server_ip }}/ftp/external-data/MD5/ /external-data/MD5/"

- name: Copy the data update script onto the mirror machine.
ansible.builtin.copy:
src: ./update-external-data.sh
dest: /external-data/update-external-data.sh
mode: '0755'

- name: Mirror the external data from the main server (this may take a while).
command: "rsync -az --perms -o -g {{ main_server_ip }}:/srv/{{ main_server_ip }}/ftp/external-data/MD5/ /external-data/MD5/"
- name: Create a crontab job that runs periodically to keep the data up to date.
ansible.builtin.cron:
name: Update external data
minute: "*/5"
job: /external-data/update-external-data.sh {{ main_server_ip }} >> /external-data/update-log.txt 2>&1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh

SERVER_IP=${1}

RSYNC_PROCESS_IDS=$(pidof rsync)

if [[ -z $RSYNC_PROCESS_IDS ]]; then
rsync -az --perms -o -g $SERVER_IP:/srv/$SERVER_IP/ftp/external-data/MD5/ /external-data/MD5/
else
echo "rsync is already running. Skipping this time..."
fi

0 comments on commit 6972988

Please sign in to comment.