| 1 | #!/bin/bash |
| 2 | # ==> Script by James R. Van Zandt, and used here with his permission. |
| 3 | |
| 4 | # ==> Comments added by author of this document. |
| 5 | |
| 6 | |
| 7 | HERE=`uname -n` # ==> hostname |
| 8 | THERE=bilbo |
| 9 | echo "starting remote backup to $THERE at `date +%r`" |
| 10 | # ==> `date +%r` returns time in 12-hour format, i.e. "08:08:34 PM". |
| 11 | |
| 12 | # make sure /pipe really is a pipe and not a plain file |
| 13 | rm -rf /pipe |
| 14 | mkfifo /pipe # ==> Create a "named pipe", named "/pipe" ... |
| 15 | |
| 16 | # ==> 'su xyz' runs commands as user "xyz". |
| 17 | # ==> 'ssh' invokes secure shell (remote login client). |
| 18 | su xyz -c "ssh $THERE \"cat > /home/xyz/backup/${HERE}-daily.tar.gz\" < /pipe"& |
| 19 | cd / |
| 20 | tar -czf - bin boot dev etc home info lib man root sbin share usr var > /pipe |
| 21 | # ==> Uses named pipe, /pipe, to communicate between processes: |
| 22 | # ==> 'tar/gzip' writes to /pipe and 'ssh' reads from /pipe. |
| 23 | |
| 24 | # ==> The end result is this backs up the main directories, from / on down. |
| 25 | |
| 26 | # ==> What are the advantages of a "named pipe" in this situation, |
| 27 | # ==>+ as opposed to an "anonymous pipe", with |? |
| 28 | # ==> Will an anonymous pipe even work here? |
| 29 | |
| 30 | # ==> Is it necessary to delete the pipe before exiting the script? |
| 31 | # ==> How could that be done? |
| 32 | |
| 33 | |
| 34 | exit 0 |