mini_image icon indicating copy to clipboard operation
mini_image copied to clipboard

no way to skip mounted smb drives

Open wiejakp opened this issue 9 years ago • 0 comments

I'm making backup of my SD card to local drive. It actually tries to bake a backup of the mounted drive as well.

Example script:

#!/bin/bash

server='//10.0.0.10/share'
mount='/home/przemek/Desktop/mnt'
host=$HOSTNAME
path="$mount/$host"
host_server="$server/$host"
host_path="$mount/$host"
host_backup="$mount/$host/backup"

# sudo mount //10.0.0.10/share /home/przemek/Desktop/mnt/ -o $( cat passwd )
# sudo mount //10.0.0.10/share /home/przemek/Desktop/mnt/ -o $( sudo cat passwd )

script=$(realpath $0)
root=$(dirname ${script})

date=$(date +%Y-%m-%d_%H-%M-%S)
os=$(lsb_release -is | awk '{print tolower($0)}')
release=$(lsb_release -rs | awk '{print tolower($0)}')
filename="$host-$os-$release-$date.img"

mount_init_dir() { 
	if [ ! -d "$mount" ]; then
		mkdir $mount
	fi
				
	if [ -d "$mount" ]; then
		return 0
	else
		return 1
	fi
}

mount_init_mount() {
	if ! grep -qs "$mount" /proc/mounts; then
		mount $server $mount -o $( sudo cat $root/passwd )
	fi

	if grep -qs "$mount" /proc/mounts; then
		return 0
	else
		return 1
	fi
}

mount_init_host() {
	if [ ! -d "$path" ]; then
		mkdir "$path"
	fi
		
	if [ -d "$path" ]; then
		return 0
	else
		return 1
	fi
}

mount_init_exit() {
	if grep -qs "$mount" /proc/mounts; then
		umount $mount
	fi
	
	if ! grep -qs "$mount" /proc/mounts; then
		return 0
	else
		return 1
	fi
}

mount_finish() {
#	echo 'Print Q to exit...'
#	echo ''
#	
#	while true; do
#		read -t 1 -n 1 key
#
#		if [[ $key = q ]]; then
#			break
#		fi
#	done
	
	while true; do
		echo 'checking if mount removed'
		
		if mount_init_exit; then
			break
		else
			sleep 1
		fi
	done
	
	echo ''
	echo 'Done!'
	echo ''
}

maunt_backup() {
	$root/mini_image.sh $host_backup/$filename
	
	echo 'Backup done...'
}

mount_init() {
	while true; do
		echo "checking if mount dir exist..."
		
		if mount_init_dir; then
			break
		else
			sleep 1
		fi
	done

	while true; do
		echo "checking if mount created"
		
		if mount_init_mount; then
			break
		else
			sleep 1
		fi
	done

	while true; do
		echo "checking if host file created"
		
		if mount_init_host; then
			echo "Mount point created: $mount"
			break
		else
			sleep 1
		fi
	done
}

mount_init
maunt_backup
mount_init_exit

exit 0

wiejakp avatar Jan 07 '17 12:01 wiejakp