LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-14-2012, 10:34 PM   #1
patrick295767
Member
 
Registered: Feb 2006
Distribution: FreeBSD, Linux, Slackware, LFS, Gparted
Posts: 664

Rep: Reputation: 138Reputation: 138
Ideas to backup a harddisk over SSH with crontab?


Hi,

I have two machines that would be ideally suited for ssh-distant backup.

I would like to operate it with crontab.

The problem is that ssh may ask for a password, and I do not like to leave a clear password in the box.

Which methods / techniques could be proposed?

Both machines are using debian Stable (Squeeze).

thank you
 
Old 07-14-2012, 10:44 PM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
You can use key-based authentication for that. http://support.suso.com/supki/SSH_Tu...nerating_a_key
 
Old 07-15-2012, 01:11 AM   #3
em31amit
Member
 
Registered: Apr 2012
Location: /root
Distribution: Ubuntu, Redhat, Fedora, CentOS
Posts: 190

Rep: Reputation: 55
first configure SSH-keys without password and then use scp for copying/backup the things.
 
Old 07-20-2012, 04:50 PM   #4
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
I generally use rsync instead of scp, but the SSH keys thing works for rsync too. Right now I'm using this script for daily backups. It's not the MOST efficient it could be, but it works for me.

Code:
#!/bin/bash
cd $HOME

if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
fi

DEST=/mnt/BACKUP/andy
DEST2=Mint32:$HOME/BACKUP/Videos
NOWDATE=$(date +%F_%H%M)


OPTS="-avhr --backup --backup-dir=$DEST/axeIncBackups_$NOWDATE --delete --exclude-from=$HOME/Documents/rsync-x.cfg"
OPTS2="-avhr --backup --backup-dir=$HOME/BACKUP/Videos_$NOWDATE --delete "

# The directories in rsync-files.cfg contain smaller stuff like documents
# and pictures, backed up to a flash drive ($DEST)
ionice -c3 rsync \
$OPTS --files-from=$HOME/Documents/rsync-files.cfg / $DEST/axeBackups

if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
fi
	

# Lot of small files potentially, so compress the backups
ionice -c3 tar cvzf $DEST/axeIncBackups_$NOWDATE.tar.gz $DEST/axeIncBackups_$NOWDATE && rm -rf $DEST/axeIncBackups_$NOWDATE

if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
fi


# backups are removed after 30 days
find $DEST -name "axeIncBackups_*" -mtime +30 -print0 | xargs -0 /bin/rm -vrf

if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
fi


# test to see if the host is up
ping -s 1 -r -c 1 -W 1 Mint32

if [ $? == 0 ]; then
{
    # copy what was done above to a drive on the LAN
    ionice -c3 rsync -avh --delete $DEST andy@Mint32:~/BACKUP
    if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
    fi

    # Now do bigger files to a drive on the LAN
    nice -n 19 ionice -c3 rsync $OPTS2 $HOME/Videos $DEST2
    if [ $? != 0 ]; then
	echo "Error, check config"
	exit 1
    fi

}
fi

echo "Daily backup done on `date`" >> $HOME/var/log/backup.log
exit 0;
Using rsync I once deleted a lot of files when forgetting a slash (I was using the --delete option) so be careful of that. rsync has a dry run option (-n) so you can see what would happen without it doing anything.
 
Old 07-23-2012, 12:22 AM   #5
patrick295767
Member
 
Registered: Feb 2006
Distribution: FreeBSD, Linux, Slackware, LFS, Gparted
Posts: 664

Original Poster
Rep: Reputation: 138Reputation: 138
So great post. Thanks so much.

Regarding the CPU use, is rsync consuming less than SCP? I have tried fuse sshfs and to operate the copy. It used too much CPU...

(I will try again soon...and post)
 
Old 07-23-2012, 02:56 PM   #6
Andy Alt
Member
 
Registered: Jun 2004
Location: Minnesota, USA
Distribution: Slackware64-stable, Manjaro, Debian64 stable
Posts: 528

Rep: Reputation: 167Reputation: 167
I've never compared, and never noticed any resource problems.

Quote:
(I will try again soon...and post)
Yeah, try it and see if you like it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
any ideas how to mount a harddisk/stick using mount via BUS METHOD? frenchn00b Linux - General 2 12-10-2009 01:22 PM
Any ideas how to sending emails using crontab and freeshell? frenchn00b Linux - General 3 10-16-2009 02:46 PM
Looking for backup solutions/ideas...somewhat long cbjhawks SUSE / openSUSE 4 09-11-2006 05:43 PM
Ubuntu 6.06 - Backup server ideas The slayer Ubuntu 4 06-17-2006 05:42 AM
Backup Ideas? jgaraas Linux - Software 1 05-06-2003 01:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 09:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration