X893

Save disk image to FTP server

Save disk partition to FTP server with zip.

#!/bin/sh

ftpfile=/$HOME/.netrc

user_pass_server=$1
diskpart=$2
file=$3
bs=$4
count=$5

user=`echo $user_pass_server | sed 's/:.*$//'`
password=`echo $user_pass_server | sed 's/.*://' | sed 's/@.*//'`
server=`echo $user_pass_server | sed 's/.*.@//'`

if [ "$user" = "$user_pass_server" -o "$user" = "$server" ] ; then
    user=anonymous
    password=xxx@xxx.xxx
fi

if [ "$diskpart" = "" ] ; then
    diskpart=sda1
fi

if [ "$bs" = "" ] ; then
    bs=1M
fi

if [ "$file" = "" ] ; then
    file=$diskpart.img.gz
fi

if [ "$server" = "" ] ; then
    echo "Usage: $0 [user:password@]ftp_servers_ip [src_partition] [dst_file] [count] [bs]"
    echo ""
    echo "default: user=$user, password=$password, file=$file, partition=$diskpart, count=$count, bs=$bs"
    exit 1
fi

rm -f $ftpfile
echo >>$ftpfile default login $user password $password
echo >>$ftpfile macdef init
echo >>$ftpfile cd img
echo >>$ftpfile bin
echo >>$ftpfile put - $file
echo >>$ftpfile quit
echo >>$ftpfile

chmod 700 $ftpfile

echo "working...Press ^C to cancel backup at any time."
if [ "$count" = "" ] ; then
    dd if=/dev/$diskpart ibs=$bs obs=1024 | gzip -9c - | ftp $server
else
    dd if=/dev/$diskpart ibs=$bs obs=1024 count=$count | gzip -9c - | ftp $server
fi

echo
echo "Backup done..."

rm -f $ftpfile


 

To restore disk partition use:
gunzip /sda.img.gz - | dd of=/dev/sda

1 comment(s) so far

  1. owner's saved my ass many times, I use it to copy VPS FTP

Post your comment

Thanks for your comments

  • Comment

Github
Bitbucket
SF.net

Skype
Telegram

Subscribe to x893 blog Subscribe