From 3753cd895a71bdbd616502368f98d4d441a2664a Mon Sep 17 00:00:00 2001 From: Andreas Ellewsen <andreas.ellewsen@usit.uio.no> Date: Thu, 14 Jan 2021 14:04:22 +0100 Subject: [PATCH] Add scripts used on VM for cristin-ms --- scripts/cristin-cleanup.service | 13 +++++++++++++ scripts/cristin-cleanup.sh | 5 +++++ scripts/cristin-cleanup.timer | 11 +++++++++++ scripts/cristin-upload.service | 13 +++++++++++++ scripts/cristin-upload.timer | 8 ++++++++ scripts/upload.sh | 34 +++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 scripts/cristin-cleanup.service create mode 100644 scripts/cristin-cleanup.sh create mode 100644 scripts/cristin-cleanup.timer create mode 100644 scripts/cristin-upload.service create mode 100644 scripts/cristin-upload.timer create mode 100644 scripts/upload.sh diff --git a/scripts/cristin-cleanup.service b/scripts/cristin-cleanup.service new file mode 100644 index 0000000..6998f51 --- /dev/null +++ b/scripts/cristin-cleanup.service @@ -0,0 +1,13 @@ +[Unit] +Description=Cristin cleanup +After=network.target + +[Service] +Type=simple +User=bottint +WorkingDirectory=/home/bottint/cristin/uib/prod/archive +ExecStart=/usr/local/bin/cristin-cleanup.sh + +[Install] +WantedBy=multi-user.target + diff --git a/scripts/cristin-cleanup.sh b/scripts/cristin-cleanup.sh new file mode 100644 index 0000000..4499e5b --- /dev/null +++ b/scripts/cristin-cleanup.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +printf "Deleting files older than 30 days" +find -maxdepth 1 -name "*.xml" -mtime +30 -exec rm {} \; + diff --git a/scripts/cristin-cleanup.timer b/scripts/cristin-cleanup.timer new file mode 100644 index 0000000..db0711f --- /dev/null +++ b/scripts/cristin-cleanup.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly cristin export upload + +[Timer] +OnCalendar=Sun 4:15 +AccuracySec=24h +Persistent=true + +[Install] +WantedBy=timers.target + diff --git a/scripts/cristin-upload.service b/scripts/cristin-upload.service new file mode 100644 index 0000000..f2b98c0 --- /dev/null +++ b/scripts/cristin-upload.service @@ -0,0 +1,13 @@ +[Unit] +Description=Cristin export upload +After=network.target + +[Service] +Type=simple +User=bottint +WorkingDirectory=/home/bottint/cristin/uib/prod +ExecStart=/usr/local/bin/upload.sh + +[Install] +WantedBy=multi-user.target + diff --git a/scripts/cristin-upload.timer b/scripts/cristin-upload.timer new file mode 100644 index 0000000..e290c46 --- /dev/null +++ b/scripts/cristin-upload.timer @@ -0,0 +1,8 @@ +[Timer] +OnCalendar=Sat 4:15 +AccuracySec=24h +Persistent=true + +[Install] +WantedBy=timers.target + diff --git a/scripts/upload.sh b/scripts/upload.sh new file mode 100644 index 0000000..86ee71f --- /dev/null +++ b/scripts/upload.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Upload script + +COUNT=0 + +rm sftp_batch.tmp +# Find files and write batchfile to be passed to sftp +for output in $(ls *.xml -1) +do + COUNT=1 + printf "put -P \"$output\"\n" >> sftp_batch.tmp +done + +# Exit if nothing to upload +if [[ $COUNT -eq 0 ]]; then + #printf "$0: No files to upload" >$2 + exit 1 +fi + +# Output which commands we will be running +#printf "Connecting with sftp and executing following commands:\n" +#printf "$(<sftp_batch.tmp)" + +sftp -b sftp_batch.tmp cristin-export@norzola.uio.no:cristin/ || exit 1 +#scp $output cristin-export@norzola.uio.no:cristin/ || exit + +#Archive transferred files +for output in $(ls *.xml -1) +do + mv $output archive/ +done + +rm sftp_batch.tmp + -- GitLab