She wanted the commands to run serially and not in the background
so don't use ampersands, also she wanted verbosity but not necessarily
to dump to files, so I'd suggest making a file called backup.sh that
contains:
Code:
#!/bin/sh
mount /dev/sdb1 /iscsi
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/
rsync -vrplogDtH /home/ /iscsi/home/
this is already verbose because of the -v option being used
on rsync. To retain the verbose output to a file just do:
if the shell is tcsh or csh: backup.sh >& outputfile
if the shell is bash or sh: backup.sh > output 2>&1
If you always want to write to the file, it makes more sense to put
the redirection in the backup.sh
Code:
#!/bin/sh
mount -v /dev/sdb1 /iscsi > outputfile 2>&1
rsync -vrplogDtH /var/lib/mysql/ /iscsi/mysql/ >> outputfile 2>&1
rsync -vrplogDtH /home/ /iscsi/home/ >> outputfile 2>&1
There's a few correctness things wrong with this, nowadays you'd
usually not do:
mount /dev/sdb1 /iscsi > outputfile 2>&1
but rather use mount's -L option flag to mount the device by
the filesystem label (you'd have to use e2label to set the
filesystems label to MyBackup)
mount -vL MyBackup > outputfile
and your /etc/fstab would have a related entry to associate
that with /iscsi:
LABEL=MyBackup /iscsi ext3 defaults,noatime 1 2
The problem with hardcoding /dev/sdb1 is that
sometime you might plug in some other usb devices before the
drive that has your iscsi named volume. That might make linux
map it to /dev/sdc1 and your script will break. Since mount -L
uses the actual label in the filesystem it mounts the right drive
each time no matter what the order the devices are found.
Mark