Skip to main content
Code Review

Return to Question

Tweeted twitter.com/StackCodeReview/status/715269248608821249
edited tags
Link
janos
  • 112.9k
  • 15
  • 154
  • 396
added 11 characters in body; edited tags; edited title
Source Link
200_success
  • 145.5k
  • 22
  • 190
  • 479

Simple shell backup script to backup to Amazon over iSCSI

Some other questionquestions that I have:

  1. After the backup is complete is it necessary/better to logout from the amazon and unmount the volume?

    After the backup is complete is it necessary/better to logout from the amazon and unmount the volume?
  2. Is it better to check if the volume is mounted based on the UUID?

    #!/bin/bash

    VARIABLES

    BACKUP_FROM="/folder/" BACKUP_TO="/folder/" LOG_FILE="/var/log/backup.log" SCSI="/sbin/iscsiadm" VOL="ghrryhfd-56655565-456456-3453-dfhthjtrrgg"

    SCRIPT

    Check that the log file exists

    if [ ! -e "$LOG_FILE" ]; then touch "$LOG_FILE" fi

    Check if the volume is mounted if not login to amazon and mount

    if mountpoint -q /mount_folder; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Volume mounted" >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - Mounting!" >> "$LOG_FILE" $SCSI --mode node --targetname abc.222-99.com.amazon:volume_name --portal 1.1.1.1:9999 --login sleep 10 mount -U "$VOL" /mount_folder sleep 8 fi

    Start entry in the log

    echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"

    Start sync

    if rsync -a -v "$BACKUP_FROM" "$BACKUP_TO" &>> "$LOG_FILE"; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync completed succesfully." >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: rsync-command failed." >> "$LOG_FILE" echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE" echo "" >> "$LOG_FILE" exit 1 fi

    End entry in the log

    echo "" >> "$LOG_FILE" exit 0

    Is it better to check if the volume is mounted based on the UUID?
#!/bin/bash
##
## VARIABLES
##
BACKUP_FROM="/folder/"
BACKUP_TO="/folder/"
LOG_FILE="/var/log/backup.log"
SCSI="/sbin/iscsiadm"
VOL="ghrryhfd-56655565-456456-3453-dfhthjtrrgg"
##
## SCRIPT
##
# Check that the log file exists
if [ ! -e "$LOG_FILE" ]; then
 touch "$LOG_FILE"
fi
# Check if the volume is mounted if not login to amazon and mount
if mountpoint -q /mount_folder; then
echo "$(date "+%Y-%m-%d %k:%M:%S") - Volume mounted" >> "$LOG_FILE"
else
echo "$(date "+%Y-%m-%d %k:%M:%S") - Mounting!" >> "$LOG_FILE"
$SCSI --mode node --targetname abc.222-99.com.amazon:volume_name --portal 1.1.1.1:9999 --login
sleep 10
mount -U "$VOL" /mount_folder
sleep 8
fi
# Start entry in the log
echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"
# Start sync
if rsync -a -v "$BACKUP_FROM" "$BACKUP_TO" &>> "$LOG_FILE"; then
 echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync completed succesfully." >> "$LOG_FILE"
else
 echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: rsync-command failed." >> "$LOG_FILE"
 echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE"
 echo "" >> "$LOG_FILE"
 exit 1
fi
# End entry in the log
echo "" >> "$LOG_FILE"
exit 0

Simple shell backup script

Some other question that I have:

  1. After the backup is complete is it necessary/better to logout from the amazon and unmount the volume?

  2. Is it better to check if the volume is mounted based on the UUID?

    #!/bin/bash

    VARIABLES

    BACKUP_FROM="/folder/" BACKUP_TO="/folder/" LOG_FILE="/var/log/backup.log" SCSI="/sbin/iscsiadm" VOL="ghrryhfd-56655565-456456-3453-dfhthjtrrgg"

    SCRIPT

    Check that the log file exists

    if [ ! -e "$LOG_FILE" ]; then touch "$LOG_FILE" fi

    Check if the volume is mounted if not login to amazon and mount

    if mountpoint -q /mount_folder; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Volume mounted" >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - Mounting!" >> "$LOG_FILE" $SCSI --mode node --targetname abc.222-99.com.amazon:volume_name --portal 1.1.1.1:9999 --login sleep 10 mount -U "$VOL" /mount_folder sleep 8 fi

    Start entry in the log

    echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"

    Start sync

    if rsync -a -v "$BACKUP_FROM" "$BACKUP_TO" &>> "$LOG_FILE"; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync completed succesfully." >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: rsync-command failed." >> "$LOG_FILE" echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE" echo "" >> "$LOG_FILE" exit 1 fi

    End entry in the log

    echo "" >> "$LOG_FILE" exit 0

Simple shell script to backup to Amazon over iSCSI

Some other questions that I have:

  1. After the backup is complete is it necessary/better to logout from the amazon and unmount the volume?
  2. Is it better to check if the volume is mounted based on the UUID?
#!/bin/bash
##
## VARIABLES
##
BACKUP_FROM="/folder/"
BACKUP_TO="/folder/"
LOG_FILE="/var/log/backup.log"
SCSI="/sbin/iscsiadm"
VOL="ghrryhfd-56655565-456456-3453-dfhthjtrrgg"
##
## SCRIPT
##
# Check that the log file exists
if [ ! -e "$LOG_FILE" ]; then
 touch "$LOG_FILE"
fi
# Check if the volume is mounted if not login to amazon and mount
if mountpoint -q /mount_folder; then
echo "$(date "+%Y-%m-%d %k:%M:%S") - Volume mounted" >> "$LOG_FILE"
else
echo "$(date "+%Y-%m-%d %k:%M:%S") - Mounting!" >> "$LOG_FILE"
$SCSI --mode node --targetname abc.222-99.com.amazon:volume_name --portal 1.1.1.1:9999 --login
sleep 10
mount -U "$VOL" /mount_folder
sleep 8
fi
# Start entry in the log
echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"
# Start sync
if rsync -a -v "$BACKUP_FROM" "$BACKUP_TO" &>> "$LOG_FILE"; then
 echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync completed succesfully." >> "$LOG_FILE"
else
 echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: rsync-command failed." >> "$LOG_FILE"
 echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE"
 echo "" >> "$LOG_FILE"
 exit 1
fi
# End entry in the log
echo "" >> "$LOG_FILE"
exit 0
Source Link
Pete
  • 43
  • 3

Simple shell backup script

The script works but I know that it can be improved. Please note that my scripting skills are very basic :) (as it can be seen in my Frankenstein script – I took bits and pieces of the code from different tutorials).

I would appreciated if someone could review this script and identify some major flaws.

Some other question that I have:

  1. After the backup is complete is it necessary/better to logout from the amazon and unmount the volume?

  2. Is it better to check if the volume is mounted based on the UUID?

    #!/bin/bash

    VARIABLES

    BACKUP_FROM="/folder/" BACKUP_TO="/folder/" LOG_FILE="/var/log/backup.log" SCSI="/sbin/iscsiadm" VOL="ghrryhfd-56655565-456456-3453-dfhthjtrrgg"

    SCRIPT

    Check that the log file exists

    if [ ! -e "$LOG_FILE" ]; then touch "$LOG_FILE" fi

    Check if the volume is mounted if not login to amazon and mount

    if mountpoint -q /mount_folder; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Volume mounted" >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - Mounting!" >> "$LOG_FILE" $SCSI --mode node --targetname abc.222-99.com.amazon:volume_name --portal 1.1.1.1:9999 --login sleep 10 mount -U "$VOL" /mount_folder sleep 8 fi

    Start entry in the log

    echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"

    Start sync

    if rsync -a -v "$BACKUP_FROM" "$BACKUP_TO" &>> "$LOG_FILE"; then echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync completed succesfully." >> "$LOG_FILE" else echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: rsync-command failed." >> "$LOG_FILE" echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE" echo "" >> "$LOG_FILE" exit 1 fi

    End entry in the log

    echo "" >> "$LOG_FILE" exit 0

default

AltStyle によって変換されたページ (->オリジナル) /