rapid_backup 4.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
#!/bin/csh
# Backup script for use on RAPID cruises
# Data is copied to an external drive connected to main workstation
# Drive mounted in /media
#
# This version by DAS Updated Tue 28th 2017.  Edited previous verions used 
# for remote backup on RAPID cruises
# 1)  syncs data from "cruise" directory, and creates a bakup of all changed files
# 2)  syncs data from "rapid/osnap"  directory, and creates a bakup of all changed files
# 3)  syncs data from "Desktop"  directory, and creates a bakup of all changed files
# When change for a new cruise need to change
# - drive names
# - $root
# - $cru

# Variables for pathnames
set cru  = jc174
set CRU = JC174
set root = /local/users/pstar/
set rapiddir = 'rapid'   # Could be osnap
set usersdir = 'users'
set progdir = 'programs'
set deskdir = 'Desktop'
set exec_loc = ${root}cruise/data/exec/rapid/

# Which drive are we using and is it there?
echo ' '
echo `date` ' Starting backup'
echo ' '
#echo -n 'Which disk are you using?   Enter '1', '2', or '3': '
#set drq = $<
set drq = $1
echo $drq
if ($drq == 1) then
  set drive_name = ${CRU}_back_1
else if  ($drq == 2) then
  set drive_name = ${CRU}_back_2
else if  ($drq == 3) then
  set drive_name = ${CRU}_back_3
else
  echo 'Input not recognised'
  exit
endif

# Drive pathname
set drive_path = '/run/media/pstar/'${drive_name}

if (-e ${drive_path}) then
   echo Drive connected
else
   echo ${drive_path} ' Does not seem to be there'
#   exit
endif 

# Create a logfile for the backup
set now = `date +%Y%m%d%H%M%S`
set backuplog = ${drive_path}/backup_logs/backup_log_${now}
if (-e $backuplog) then
  echo $backuplog exists
  exit
else
  touch $backuplog
endif

# -----------------------------------------------------------------
# First backup the cruise directory
set root_path_cru = ${root}rpdmoc/${cru}
set sync_cru =  ${drive_path}/cruise_${cru}_sync_$drq
set back_cru =  ${drive_path}/cruise_${cru}_back_$drq/backup_${now}

# Call the main routine
# ----------------------------------------------------
${exec_loc}backup_core_local $root_path_cru $sync_cru $back_cru $backuplog
# ----------------------------------------------------

# --------------------------------------------------------------------
# Sync all of the RAPID directory
set now = `date +%Y%m%d%H%M%S`
set root_path_rap = ${root}rpdmoc/$rapiddir
set sync_rap =  ${drive_path}/${rapiddir}_${cru}_sync_$drq
set back_rap =  ${drive_path}/${rapiddir}_${cru}_back_$drq/backup_${now}

# Call the main routine
# ----------------------------------------------------
${exec_loc}backup_core_local $root_path_rap $sync_rap $back_rap $backuplog
# ----------------------------------------------------

# --------------------------------------------------------------------
# Sync all of the users directory
set now = `date +%Y%m%d%H%M%S`
set root_path_users = ${root}rpdmoc/$usersdir
set sync_users =  ${drive_path}/${usersdir}_${cru}_sync_$drq
set back_users =  ${drive_path}/${usersdir}_${cru}_back_$drq/backup_${now}

# Call the main routine
# ----------------------------------------------------
${exec_loc}backup_core_local $root_path_users $sync_users $back_users $backuplog
# ----------------------------------------------------

# --------------------------------------------------------------------
# Sync all of the programs directory
set now = `date +%Y%m%d%H%M%S`
set root_path_prog = $root$progdir
set sync_prog =  ${drive_path}/${progdir}_${cru}_sync_$drq
set back_prog =  ${drive_path}/${progdir}_${cru}_back_$drq/backup_${now}

# Call the main routine
# ----------------------------------------------------
${exec_loc}backup_core_local $root_path_prog $sync_prog $back_prog $backuplog
# ----------------------------------------------------

# --------------------------------------------------------------------
# Sync all of the Desktop directory
set now = `date +%Y%m%d%H%M%S`
set root_path_desk = $root$deskdir
set sync_desk = ${drive_path}/desk_${cru}_sync_$drq
set back_desk = ${drive_path}/desk_${cru}_back_$drq/backup_${now}

# Call the main routine
# ----------------------------------------------------
${exec_loc}backup_core_local $root_path_desk $sync_desk $back_desk $backuplog
# ----------------------------------------------------

# ------------------------------------------------------------------
# And finally copy log of backup to the disk
set olog = /backup_logs

# Don't want to time out on password so check ok now
echo ' '
echo '-----------------------------'
#echo 'Press return to copy:' $backuplog $root_path_cru$olog
# set qqq = $<
scp $backuplog $root_path_cru$olog
echo ' '
echo `date` - Backup finished