We use cookies to ensure you get the best experience on our website.
NFS
#!/bin/bash
# Configuration variables
NFS_SERVER="nfs.server.com"
NFS_EXPORT="/export"
LOCAL_MOUNT_POINT="/mnt/nfs"
LOCAL_DIRECTORY="/local/directory"
REMOTE_DIRECTORY="/mnt/nfs/remote/directory"
# Function to mount NFS
mount_nfs() {
echo "Mounting NFS..."
sudo mkdir -p "$LOCAL_MOUNT_POINT"
sudo mount -t nfs "$NFS_SERVER:$NFS_EXPORT" "$LOCAL_MOUNT_POINT"
}
# Function to unmount NFS
umount_nfs() {
echo "Unmounting NFS..."
sudo umount "$LOCAL_MOUNT_POINT"
}
# Checking if NFS is already mounted
if mount | grep "$LOCAL_MOUNT_POINT" > /dev/null; then
echo "NFS already mounted. Remounting..."
umount_nfs
mount_nfs
else
echo "NFS is not mounted. Mounting..."
mount_nfs
fi
# Synchronizing data with rsync
echo "Synchronizing data with rsync..."
rsync -avz "$LOCAL_DIRECTORY/" "$REMOTE_DIRECTORY/"
# Unmounting NFS after synchronization
umount_nfs
echo "Synchronization completed."
SAMBA
#!/bin/bash
# Configuration variables
SAMBA_SERVER="//samba.server.com/share"
MOUNT_OPTIONS="username=user,password=pass"
LOCAL_MOUNT_POINT="/mnt/samba"
LOCAL_DIRECTORY="/local/directory"
REMOTE_DIRECTORY="/mnt/samba/remote/directory"
# Function to mount Samba share
mount_samba() {
echo "Mounting Samba share..."
sudo mkdir -p "$LOCAL_MOUNT_POINT"
sudo mount -t cifs -o "$MOUNT_OPTIONS" "$SAMBA_SERVER" "$LOCAL_MOUNT_POINT"
}
# Function to unmount Samba share
umount_samba() {
echo "Unmounting Samba share..."
sudo umount "$LOCAL_MOUNT_POINT"
}
# Checking if Samba share is already mounted
if mount | grep "$LOCAL_MOUNT_POINT" > /dev/null; then
echo "Samba share already mounted. Remounting..."
umount_samba
mount_samba
else
echo "Samba share is not mounted. Mounting..."
mount_samba
fi
# Synchronizing data with rsync
echo "Synchronizing data with rsync..."
rsync -avz "$LOCAL_DIRECTORY/" "$REMOTE_DIRECTORY/"
# Unmounting Samba share after synchronization
umount_samba
echo "Synchronization completed."
Cześć Podróżniku!
Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.
Wszelkie prawa zastrzeżone
Dodaj komentarz