bash script : rsync only if device mounted

 

The script checks if the location to backup the files to is a mountpoint. If not, the script should mount it or die. If it is a mountpoint, rsync should be run.

 

here goes

 

#!/bin/bash

##
## VARIABLES
##

# Set source location
BACKUP_FROM="/srv/media/"

# Set target location
BACKUP_TO="/media/backup/media/"
BACKUP_DEV="xxxxxxx-xxxxx-xxxxxxxxxxxxxxx" #UUID of the disk
BACKUP_MNT="/media/backup"

# Log file
LOG_FILE="/var/log/script_sync_media.log"

##
## SCRIPT
##

# Check that the log file exists
if [ ! -e "$LOG_FILE" ]; then
        touch "$LOG_FILE"
fi

# Check that source dir exists and is readable.
if [ ! -r  "$BACKUP_FROM" ]; then
        echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to read source dir." >> "$LOG_FILE"
        echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE"
        echo "" >> "$LOG_FILE"
        exit 1
fi

# Check that target dir exists and is writable.
if [ ! -w  "$BACKUP_TO" ]; then
        echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to write to target dir." >> "$LOG_FILE"
        echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE"
        echo "" >> "$LOG_FILE"
        exit 1
fi

# Check if the drive is mounted
if ! mountpoint "$BACKUP_MNT"; then
        echo "$(date "+%Y-%m-%d %k:%M:%S") - WARNING: Backup device needs mounting!" >> "$LOG_FILE"

        # If not, mount the drive
        if [ mount -U "$BACKUP_DEV" "$BACKUP_MNT" ]; then
                echo "$(date "+%Y-%m-%d %k:%M:%S") - Backup device mounted." >> "$LOG_FILE"
        else
                echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to mount backup device." >> "$LOG_FILE"
                echo "$(date "+%Y-%m-%d %k:%M:%S") - ERROR: Unable to sync." >> "$LOG_FILE"
                echo "" >> "$LOG_FILE"
                exit 1
        fi
fi

# Start entry in the log
echo "$(date "+%Y-%m-%d %k:%M:%S") - Sync started." >> "$LOG_FILE"

# Start sync
if rsync -a -v --delete "$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

# Unmount the drive so it does not accidentally get damaged or wiped
if [ umount "$BACKUP_MNT" ]; then
	echo "$(date "+%Y-%m-%d %k:%M:%S") - Backup device unmounted." >> "$LOG_FILE"
else
	echo "$(date "+%Y-%m-%d %k:%M:%S") - WARNING: Backup device could not be unmounted." >> "$LOG_FILE"
fi

# End entry in the log
echo "" >> "$LOG_FILE"
exit 0

how to take screenshot in Mac OS x

Shortcuts

  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

In Leopard and later, the following keys can be held down while selecting an area (via Command-Shift-4 or Command-Control-Shift-4):

  • Space, to lock the size of the selected region and instead move it when the mouse moves
  • Shift, to resize only one edge of the selected region
  • Option, to resize the selected region with its center as the anchor point

html meta redirect to different site

However, when using this HTML redirect code, please ensure that you don’t use it to trick the Search Engines, as this could get your web site banned. It is always best to work hard and learn quality ways in which to drive traffic to your web site.

Place the following HTML redirect code between the <HEAD> and </HEAD> tags of your HTML code.

 

 

 

<meta HTTP-EQUIV=”REFRESH” content=”0; url=http://www.yourdomain.com/index.html”>

 

changing root password mountion lion

Enable the root user

  1. Choose Apple menu > System Preferences, and then click Users & Groups.
  2. Click the lock icon to unlock it, and then type an administrator name and password.
  3. In the Network Account Server section, click Join or Edit.
  4. Click Open Directory Utility.
  5. Click the lock icon to unlock it, and then enter your administrator name and password.
  6. Choose Edit > Enable Root User, and then enter a root user password in the Password and Verify fields.Be sure to specify a secure password.

Change the root user password

  1. Choose Apple menu > System Preferences, and then click Users & Groups.
  2. Click the lock icon to unlock it, and then type an administrator name and password.
  3. In the Network Account Server section, click Join or Edit.
  4. Click Open Directory Utility.
  5. Click the lock icon to unlock it, and then enter your administrator name and password.
  6. Choose Edit > Change Root Password, and then enter a root user password in the Password and Verify fields.Be sure to specify a secure password.

Directory-Utility-Disable-Root

WP Twitter Auto Publish Powered By : XYZScripts.com