Jump to content

BASH: SSHFS Backup Script

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Guest_Jordan_*

Guest_Jordan_*
  • Guests
This script uses Fuse/SSHFS to mount a remote machine via SSH as a local drive. Once mounted, any file(s) can be copied just like a local drive.

#!/bin/sh
##
# Description: SSH/Fuse mount, backup and umount script. 
#                  Execute via cron for schedule backups over 
#                  secure shell.
#
# Author: Jordan DeLozier
# Date: 1-19-2009
# Usage: ./BackupScript.sh
#
# Must run as root
# Must use SSH Key Authentication for automatic updates
##

# For some reason the kernel module doesn't always
# load on boot. Load it now
/sbin/modprobe fuse

# Mount the remote SSH machine, if there
# is an error exit. This prevents the files from
# being copied to the local machine and using
# local hard disk space
#
# Replace <username>,<server>,/path/to/files/ and /mnt/<dir> with
# proper values.
##
if (!(/usr/local/bin/sshfs <username>@<server>:/path/to/files/ /mnt/<dir>)); then
        echo "Mount Failed"
        exit 1
fi

# Copy the Files
# Using -Ru recursively copies and only copies
# files that are different from the target. 
# 
# Replace /source/files and /mnt/<dir of mount>
##
cp -Ru /source/files/ /mnt/<dir of mount>

# Unmount
#
# Replace /mnt/<dir of mount>
##
umount /mnt/<dir of mount>

Use it, change it, distribute it. Please consider linking back to the source when you do if possible.

Edited by Jordan, 17 June 2009 - 12:04 PM.


#2
kiddies

kiddies

    Programmer

  • Members
  • PipPipPipPip
  • 130 posts
its work properly.....hey can u give me an algorithma

#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Huh? Algorithm for what?