自动同步硬盘和u盘上的文件

前端之家收集整理的这篇文章主要介绍了自动同步硬盘和u盘上的文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash
#rsync the hard disk files to usb disks
#usage: HDF2UDrsync  USBDISKNAME
#example: HDF2UDrsync sdb1
#the usb disk mount point is ${upath}
#usb device
if [ $# -ne 1 ]
then
	echo Usage: $(basename $0) USBDISKNAME
	echo example: $(basename $0) sdb1
	exit
fi
udevice="/dev/$1"
#usb disk mount point
upath=$(mktemp -d -t usbdisk229XXXXXX)'/'
hpath='/media/sda2/'
#source files
sf=("${hpath}lsoftware/" "${hpath}software/" "${hpath}document/" "${hpath}ghost/iso/slconfig/" "/home/000/Documents/fp/")
#destination files
df=("${upath}lsoftware/" "${upath}software/" "${upath}docs/" "${upath}iso/slconfig/" "${upath}fp/")
#mount ${udevice} on ${upath}
if [ ! -b ${udevice} ]
then
	echo "${udevice} : No such device,exit!"
	exit
fi
sudo umount ${udevice} 2> /dev/null
sudo mount ${udevice} ${upath}
clear
#rsync the files
#full rsync
for i in {0,1,2,3,4}
#partial rsync
#for i in {3,4}
do
	echo ${sf[i]} '======>>>>>>'  ${df[i]}
	#--exclude='*.bak'
	rsync\
		--specials --partial --delete --links\
		--recursive --times --update --verbose\
		--progress --human-readable\
		--exclude ".0/"\
		--exclude "vimPUNDO/"\
		--exclude "*.iso"\
		--exclude "*.mkv"\
		${sf[i]} ${df[i]}
done
#umount ${udevice}
sudo umount ${udevice}
rm -rf ${upath}

#===========================================================================

#!/bin/bash
#rsync the hard disk files to usb disks
#usage: UDF2HDrsync  USBDISKNAME
#example: UDF2HDrsync sdb1
#the usb disk mount point is ${upath}
#usb device
if [ $# -ne 1 ]
then
	echo Usage: $(basename $0) USBDISKNAME
	echo example: $(basename $0) sdb1
	exit
fi
udevice="/dev/$1"
#usb disk mount point
upath=$(mktemp -d -t usbdisk229XXXXXX)'/'
hpath='/media/sda2/'
#source files
sf=("${upath}lsoftware/" "${upath}software/" "${upath}docs/" "${upath}iso/slconfig/" "${upath}fp/")
#destination files
df=("${hpath}lsoftware/" "${hpath}software/" "${hpath}document/" "${hpath}ghost/iso/slconfig/" "/home/000/Documents/fp/")
#mount ${udevice} on ${upath}
if [ ! -b ${udevice} ]
then
	echo "${udevice} : No such device,4}
do
	echo ${sf[i]} '======>>>>>>'  ${df[i]}
	#--exclude='*.bak'
	rsync\
		--specials --partial --delete --links\
		--recursive --times --update --verbose\
		--progress --human-readable\
		--exclude ".0/"\
		--exclude "vimPUNDO/"\
		--exclude "*.iso"\
		--exclude "*.mkv"\
		${sf[i]} ${df[i]}
done
#umount ${udevice}
sudo umount ${udevice}
rm -rf ${upath}

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

猜你在找的Shell相关文章