Difference between revisions of "Linux Rsync Backup"
Jump to navigation
Jump to search
Line 8: | Line 8: | ||
* Make it executable (eg, '''chmod a+x backup'''. | * Make it executable (eg, '''chmod a+x backup'''. | ||
* Enable wifi on your Pre (you'll need its current IP address), or start your emulator. | * Enable wifi on your Pre (you'll need its current IP address), or start your emulator. | ||
− | * To | + | * You'll need to know how to ssh as root to your pre with a password. You can set this up temporarily: |
+ | ssh -p222 your_user@pre_ip_address | ||
+ | sudo bash -- give your user password, then you're root | ||
+ | /usr/sbin/rootfs_open -w | ||
+ | passwd root | ||
+ | mount -o remount,ro / | ||
+ | exit | ||
+ | |||
+ | * To use the script with your emulator: | ||
linuxbox$ ./backup localhost 5522 root | linuxbox$ ./backup localhost 5522 root |
Revision as of 17:49, 27 December 2009
Here is a first cut at a backup script which will pull from a linux host. It will create an SSH public key pair if none exists already, copy them to the Pre, then perform a complete rsync to the user's ~/palm directory. So far it works okay with the emulator. Feel free to fix bugs here, or on the discussion tab.
Warning - Setting up a key pair in this manner will mean a user on your linux box can get your Pre as well.
Instructions
- Make sure you have rsync and openssh installed on your Linux box.
- Save the code below to a file on your linux box (eg, backup).
- Make it executable (eg, chmod a+x backup.
- Enable wifi on your Pre (you'll need its current IP address), or start your emulator.
- You'll need to know how to ssh as root to your pre with a password. You can set this up temporarily:
ssh -p222 your_user@pre_ip_address sudo bash -- give your user password, then you're root /usr/sbin/rootfs_open -w passwd root mount -o remount,ro / exit
- To use the script with your emulator:
linuxbox$ ./backup localhost 5522 root found, using it reached the palm with ssh key receiving file list ... done ./ bin/ ... etc ...
- To run with the Pre over IP:
linuxbox$ ./backup 111.222.233.244 222 root
Note you may need to specify the user you created when you rooted the Pre instead. The user will need read access to the whole file tree.
Code
#!/bin/bash die() { echo $@ exit 1; } [ $# -eq 3 ] || die "Usage: $0 palm_ip palm_port palm_user" host=$1 port=$2 user=$3 strict='-o StrictHostKeyChecking=no' pubkey='-o PreferredAuthentications=publickey' dest="-p $port $user@$host" [ -x /usr/bin/rsync ] || die no rsync, you should: sudo apt-get install rsync if [[ ! -f ~/.ssh/id_dsa || ! -f ~/.ssh/id_dsa.pub ]]; then echo we need to make an ssh keypair ssh-keygen -q -t dsa -f ~/.ssh/id_dsa -N '' || die ssh-keygen failed else echo found, using it fi if ssh $strict $pubkey $dest ls /etc/palm > /dev/null; then echo reached the palm with ssh key else echo need to copy local pubkey to palm cmd='umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys' cat ~/.ssh/id_dsa.pub | ssh $strict $dest $cmd if ssh $strict $pubkey $dest ls /etc/palm > /dev/null; then echo second try good, reached the palm with ssh key else die could not use pubkey after installing it on the palm fi fi rsync -avz --size-only --exclude proc/ --exclude dev/ --exclude sys/ \ -e "ssh -p $port $strict" $user@$host:/ ~/palm