Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
would you please paste the /dev/xxx pathname of this device
and the output of "ls -l /dev/dsik/by-id"
I want to see, where and why it does not show up.
btw.: "unalias -a" is not needed.
Bash doesn't use aliases when invoked to run a script.
This might be necessary in other shells, but as the shebang indicates, this script is run by bash.
would you please paste the /dev/xxx pathname of this device
and the output of "ls -l /dev/dsik/by-id"
I want to see, where and why it does not show up.
btw.: "unalias -a" is not needed.
Bash doesn't use aliases when invoked to run a script.
This might be necessary in other shells, but as the shebang indicates, this script is run by bash.
ill try in the morning. i might of messed up one of the flash drive with lvcreate and gvcreate earlier today.
The find command got some options doing this with one call:
Code:
LANG=C cd /dev/disk/by-id && find . -name 'usb*' -ls
This gives all needed information. I'm not quite sure, if it is save, to parse that output.
Will going to examine that tonight (Germany GMT+1) and write a little script to prove that. And make the command interdependent from the working directory.
Doing that with UDEV rules, means to track the information of all devices used by customers.
In one way or the other you have to know the device serial number, manufacturer or some else unique information of that device.
If you can prove that true, it would be more rock solid to take this road.
If customers can use whatever device they came across, it is pointless, unless you have a script that can get this information reliable. If customer get's a new device, some kind of "setup" toachive this information has to be run.
[root@rx30 ~]# cat vgbackup.log
PV /dev/sdb1 VG vgusb lvm2 [7.54 GB / 0 free]
Total: 1 [7.54 GB] / in use: 1 [7.54 GB] / in no VG: 0 [0 ]
Reading all physical volumes. This may take a while...
Found volume group "vgusb" using metadata type lvm2
1 logical volume(s) in volume group "vgusb" now active
0 logical volume(s) in volume group "vgusb" now active
[root@rx30 ~]# cat vgback.sh
dtstamp="`date +%Y%m%d%H%M%S `"
logger -p local0.info "[Backup] Attempting backup ${dtstamp} at `date`"
LOG=vgbackup.log
### SCAN / ON-LINE
pvscan >> $LOG # Never hurts
vgscan >> $LOG # Never hurts
vgchange -ay vgusb >> $LOG
# Fail if the logical volume "backup" is not available
if [ ! -e "/dev/mapper/vgusb-backup" ] ; then
logger -p local0.warn "[Backup] USB Backup Disk Not Connected"
exit 1
fi
### MOUNT ATTEMPT
pvscan
vgscan
vgchange -ay vgusb
lvchange -ay /dev/mapper/vgusb-backup
sync
mount -t ext3 /dev/mapper/vgusb-backup /mnt/backup >> $LOG
rc=$?
if [ $rc -ne 0 ]; then
logger -p local0.warn "[Backup] Unable to mount (rc=${rc}) USB Backup Disk"
exit 2
fi
### BACKUP
# (do your backup here)
#
tarfilename=test.tar.bz
tar -cjvf $tarfilename $HOME/*
mv $tarfilename /mnt/backup/
sync ; sync
### UMOUNT / OFF-LINE
umount /dev/mapper/vgusb-backup >> $LOG
sync
lvcahnge -an /dev/mapper/vgusb-backup
vgchange -an vgusb >> $LOG
logger -p local0.info "[Backup] Completed backup ${dtstamp} at `date`"
exit 0
now i just need to figure out how to make it work for user not just root and get it so it will not break the file system when a customer is bad and removes the device while it is mounted.
Thanks for misleading people trying to help you.
You should have mentioned, that you are using device mapper.
None of your code is dealing with udev in any way.
Code:
disks=( $( find "$devdir" -name 'usb*'| grep -E -e 'part[[:digit:]]{1,2}'))
i=0
for dev in ${sticks[*]} ; do
temp=$( readlink "$dev" )
devnames[$i]=${temp##*/}
(( i = "$i" + 1 ))
done
with this code, you have an array "devnames" holding just all sdX names of each USB Drive connected, which have at least one partition.
Note: medias like a CD do not have any partition showing up as a "sdX".
Thanks for misleading people trying to help you.
You should have mentioned, that you are using device mapper.
None of your code is dealing with udev in any way.
Code:
disks=( $( find "$devdir" -name 'usb*'| grep -E -e 'part[[:digit:]]{1,2}'))
i=0
for dev in ${sticks[*]} ; do
temp=$( readlink "$dev" )
devnames[$i]=${temp##*/}
(( i = "$i" + 1 ))
done
with this code, you have an array "devnames" holding just all sdX names of each USB Drive connected, which have at least one partition.
Note: medias like a CD do not have any partition showing up as a "sdX".
no misleading at all. when i first started i was not using udev, but as time went i mentioned that is were i was heading.
Thank you for the reply, i have a working script now let me post it:
Code:
dtstamp="`date +%Y%m%d%H%M%S `"
logger -p local0.info "[Backup] Attempting backup ${dtstamp} at `date`"
LOG=vgback.log
### SCAN / ON-LINE
umount -f /mnt/backup >> $LOG
lvchange -an /dev/vgusb/backup >> $LOG
vgchange -an vgusb >> $LOH
pvscan >> $LOG # Never hurts
vgscan >> $LOG # Never hurts
vgchange -ay vgusb >> $LOG
# Fail if the logical volume "backup" is not available
if [ ! -e "/dev/mapper/vgusb-backup" ] ; then
logger -p local0.warn "[Backup] USB Backup Disk Not Connected"
exit 1
fi
### MOUNT ATTEMPT
pvscan
vgscan
vgchange -ay vgusb
lvchange -ay /dev/mapper/vgusb-backup
sync
mount -t ext3 /dev/mapper/vgusb-backup /mnt/backup >> $LOG
rc=$?
if [ $rc -ne 0 ]; then
logger -p local0.warn "[Backup] Unable to mount (rc=${rc}) USB Backup Disk"
exit 2
fi
### BACKUP
# (do your backup here)
#
#tarfilename=test.tar.bz
#tar -cjvf $tarfilename $HOME/*
#mv $tarfilename /mnt/backup/
dow=`date +%a`
[ ! -d "/mnt/backup/${dow}" ] && mkdir /mnt/backup/${dow} >> /dev/null 2>&1
rsync -aviS /usr/rx30/ /mnt/backup/${dow} >> $LOG 2>&1
sync ; sync
### UMOUNT / OFF-LINE
#umount /dev/mapper/vgusb-backup >> $LOG
umount -f /mnt/backup >> $LOG
lvchange -an /dev/vgusb/backup >> $LOG
vgchange -an vgusb >> $LOG
sync
logger -p local0.info "[Backup] Completed backup ${dtstamp} at `date`"
exit 0
Im sure it still needs to be cleaned up a bit, but this is much better then what I started out with. Looks like auto-detection of a USB device might still be out of reach for now, but this way once the LVM is setup and configured it just works.
#!/bin/bash
###########################################################
### Created by Ray Brunkow with help from Bryan Smith
###
# Copyright (C) 2012 Raymond L. Brunkow.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 or version 3 of the
# license, at your option.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
###
##########################################################
### Setting Variables
#####################################
cd /usr/rx30
license=`su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/showlic | grep LICENSE | awk '{print $6}'`
cd
dtstamp="`date +%Y-%m-%d-%H.%M.%S `"
dow=`date +%a`
log=${dtstamp}-vgback.log
rx30sessions=1
csrunning=1
####################################
### THIS IS THE ONLY ARGUMENT FOR THIS SCRIPT
# vgback.sh rsync
# if the rsync argument is called this script will NOT encrypt a tarball
# instead it will perform an archived rsync out to the USB device.
# This is great for stores who want to use large external USB harddrives and
# want to have a more up to date archive process other then once every day.
# you can set the rsync to run once every hour if they have at leats a
# Dell T3400. If they are on older hardware, set it no sooner then once
# every four (4) hours.
###
####################################
###################################
### Configure cron jobs
# crontab -e
# add a line that looks simular to this:
# */59 * * * * /root/vgback.sh
# the above line will run vgback.sh once every hour at the 59min mark.
# 0 */4 * * * /root/vgback.sh
# the above line will run vgback.sh once every four (4) hours on the hour.
# 0 21 * * * /root/vgback.sh
# the above line will run at 9pm local time every night.
###
####################################
### Checking for rsync argument
#####################################
if [ "$1" = "rsync" ]
then
echo "$1" chosen >> ${log}
fi
### Create LVM Directions.
# [1] Create your volume group (vgusb), logical volume (backup) in the
# volume group (vgusb) and filesystem on it (vgusb-backup):
# NOTE*** BTW, when you do your "vgcreate" -- make sure nothing is on
# /dev/sdb1 that you care about. ;) This is in fdisk: Also, use the slice
# ID for LVM (8E hex) instead of Ext2/3/4 (83 hex) for LVM.
#
# fdisk /dev/sdX were X is the drive letter you discover via
# dmesg or tail -f /var/log/messages
# d to delete all partitions on the USB device before you start.
# n for new partition.
# p for primary
# 1 for 1 partition
# t to change flag as to what type of partition we are creating.
# Command (m for help): t
# Selected partition 1
# Hex code (type L to list codes): 8e
# p to view that you have the correct file type for the partition:
# Command (m for help): p
#
# Disk /dev/sda: 8084 MB, 8084520960 bytes
# 249 heads, 62 sectors/track, 1022 cylinders
# Units = cylinders of 15438 * 512 = 7904256 bytes
#
# Device Boot Start End Blocks Id System
# /dev/sda1 1 1022 7888787 8e Linux LVM
#
### Now that the USB Device is partitioned correctly we can continue
### creating the LVM.
### NOTE From this point forward I will use /dev/sdb and
### /dev/sdb1 as example device/partition.
#
# pvcreate /dev/sdb1
# vgcreate vgusb /dev/sdb1
# vgchange -ay vgusb # NEVER HURTS
# lvcreate -l 100%FREE -n backup vgusb # See below if you have problems here.
# lvchange -ay /dev/mapper/vgusb-backup # NEVER HURTS
# mkfs.ext3 -j /dev/mapper/vgusb-backup
# tune2fs -c 0 /dev/mapper/vgusb-backup
# vgchange -ay vgusb
#
### This will create both the VG, LV, format the drive, and turn
### off file system checking.
#
#
# If the lvcreate -l 100%FREE -n backup vgusb gives you fit do
# the following: We will use the -L option but first we must find
# the exact number of PEs "free" in the VG
# run "vgdisplay" and you should see something like below:
# [root@rx30 ~]# vgdisplay
# WARNING: Ignoring duplicate config node: umask (seeking umask)
# --- Volume group ---
# VG Name vgusb
# System ID
# Format lvm2
# Metadata Areas 1
# Metadata Sequence No 2
# VG Access read/write
# VG Status resizable
# MAX LV 0
# Cur LV 1
# Open LV 1
# Max PV 0
# Cur PV 1
# Act PV 1
# VG Size 7.54 GB
# PE Size 4.00 MB
# Total PE 1931 # This is the line you are looking for.
# Alloc PE / Size 1931 / 7.54 GB
# Free PE / Size 0 / 0
# VG UUID d0qGoQ-DGjl-BcjA-IzTo-4mk1-SG71-9kcTrr
#
# Now you can try the lvcreate this way
# lvcreate -L 1931 -n backup vgusb #### NOTE remember this is the example,
### use the correct Total PE from your device.
# Follow the rest of the directions above to complete the creation of the LVM.
######################################
######################################
### Terminating all running Rx30 sessions
######################################
while [ ${rx30sessions} -gt 0 ];
do
echo "Terminating Rx30 sessions" >> $log
killall rx30.exe
sleep 5
rx30sessions=`ps ax | grep rx30.exe | grep -v grep | wc -l`
counter=$(($counter+1))
if [ ${counter} -gt 5 ];
then
echo "Unable to terminate all Rx30 sessions: Aborting backup" >> $log
echo "Rebooting your server may resolve this issue." >> $log
exit
fi
done
echo "All Rx30 sessions terminated." >> $log
######################################
### Terminating Central Site Service
######################################
while [ ${csrunning} -gt 0 ];
do
echo "Terminating Central Site Interface." >> $log
killall rx30css
echo $? > CSS
sleep 5
csrunning=`ps ax | grep rx30.exe | grep -v grep | wc -l`
counter=$(($counter+1))
if [ ${counter} -gt 5 ];
then
echo "Unable to terminate Central Site Interfcae: Aborting backup" >> $log
exit
fi
done
echo "Central Site Interface successfully stopped." >> $log
### Terminating interfaces
######################################
echo "Stopping additional interfaces" >> $log
killall rx30faxs
killall rx30poss
killall rx30pkgs
killall rx30drxs
killall rx30rds
killall lifeline
killall rx30ntfs
echo "Additional interfaces stopped" >> $log
### Copy system files to /usr/rx30 directory
######################################
cp -vf /etc/hosts /usr/rx30/ 2>/dev/null 1>/dev/null
cp -vf /etc/exports /usr/rx30 2>/dev/null 1>/dev/null
cp -vf /etc/dhcpd.conf 2>/dev/null 1>/dev/null
cp -vf /etc/resolv.conf 2>/dev/null 1>/dev/null
cp -vf /etc/cups/printers.conf 2>/dev/null 1>/dev/null
cp -vf /etc/sysconfig/static-routes 2>/dev/null 1>/dev/null
cp -vf /etc/sysconfig/network-scripts-ifcfg-eth0 2>/dev/null 1>/dev/null
cp -vf "/etc/sysconfig/network-scripts-ifcfg-eth0:0" 2>/dev/null 1>/dev/null
cp -vf /opt/ltsp/i386/etc/lts.conf 2>/dev/null 1>/dev/null
chown rx30:group /usr/rx30/
chmod -R 755 /usr/rx30/
echo "System files copied to /usr/rx30 directory." >> $log
### SCAN / ON-LINE
######################################
# umount anything already mounted as /mnt/backup
umount -f /mnt/backup >> $log
lvchange -an /dev/vgusb/backup >> $log # Making offline to prevent issues
vgchange -an vgusb >> $log # Making offline to prevent issues
# Scan
pvscan >> $log # Never hurts
vgscan >> $log # Never hurts
vgchange -ay vgusb >> $log
lvchange -ay /dev/vgusb/backup >> $log
sync
### Fail if the logical volume "backup" is not available
######################################
if [ ! -e "/dev/mapper/vgusb-backup" ] ; then
echo "[Backup] USB Backup Disk Not Connected" >> $log
exit 1
fi
### MOUNT ATTEMPT
#######################################
mount -t ext3 /dev/mapper/vgusb-backup /mnt/backup >> $log
rc=$?
if [ $rc -ne 0 ]; then
echo "[Backup] Unable to mount (rc=${rc}) USB Backup Disk" >> $log
exit 2
fi
### BACKUP
########################################
### Check if rsync argument was used to call script.
########################################
grep rsync ${log} >/dev/null
if [ $? = 0 ]
then
########################################
### RSYNC preserving permissions
########################################
[ ! -d "/mnt/backup/${dow}" ] && mkdir /mnt/backup/${dow} >> /dev/null 2>&1
rsync -aviS /usr/rx30/ /mnt/backup/${dow} >> ${log} 2>&1
else
########################################
### ENCRYPTED tarball
########################################
[ ! -d "/mnt/backup" ] && mkdir /mnt/backup >> /dev/null 2>&1
tar -cjvpf - /usr/rx30/* | openssl enc -aes128 -salt -out /mnt/backup/${license}-${dow}-${dtstamp}.bz2.enc -e -a -k 'foo_foo_fake_pw' >> $log 2>&1
########################################
### Comment out the above line and uncomment out the below line to change from
### encrypted tar to standard tar for increased performance
########################################
#tar -cjvpf /mnt/backup/${license}-${dow}-${dtstamp}.tar.bz /usr/rx30/* >> $log 2>&1
sync ; sync
fi
########################################
### To Decrypt
# openssl enc -aes128 -in foo.tar.bz2.enc -out foo.tar.bz2 -d -a
# The password is TDSrx30 you can see that at the end of the
# tar -cjvpf - /usr.... between the ' ' marks
# Now that is is decrypted untar it via:
# tar -xvjf foot.tar.bz2
# This will untar the file into the same directory tree as it was created in.
# You can always cp the *.enc file to /tmp before decrypting and untarring.
########################################
### UMOUNT / OFF-LINE
########################################
umount -f /mnt/backup >> $log
lvchange -an /dev/vgusb/backup >> $log
vgchange -an vgusb >> $log
sync
echo "[Backup] Completed backup ${dtstamp} at `date`" >> $log
### Restarting interfaces
########################################
echo "Restarting interfaces" >> $log
cd /usr/rx30/
if [ ${CSS} -eq 0 ]
then
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30css &
else
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30drxs &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30rds &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30faxs &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30pkgs &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30poss &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/lifeline &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30ntfs &
su rx30 -c PATH=$/usr/rx30:.;/usr/rx30/rx30.exe bg &
cd
fi
exit 0
works great. btw thank you all who helped. This works fantastic as long as you do not have to recover any of the data using MS Windows as there are no tools on the market today for Windows to access LVMs.
Working on a LiveUSB project that will save space for the creation of the LVM to run this script to keep data and then to boot from the device on a Windows system to recover data.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.