使用脚本和 CIFS 安装 NAS 共享时出错

使用脚本和 CIFS 安装 NAS 共享时出错

我使用以下 bash 脚本在本地创建 MySQL 转储并将其复制到网络共享(NAS)。

#!/bin/bash

# Define your credentials (replace with your actual values)
MYSQL_USER="your_username"
MYSQL_PASS="your_password"
DB_NAME="your_database_name"

# Define paths and network share details
LOCAL_BACKUP_DIR="/path/to/local/backups"
REMOTE_SHARE="smb://server_address/share_folder"
REMOTE_USER="network_username"
REMOTE_PASS="network_password"

# Get current date
DATE=$(date +%Y-%m-%d)

# Create local backup directory if it doesn't exist
mkdir -p "$LOCAL_BACKUP_DIR"

# Dump the database and compress it
mysqldump -u "$MYSQL_USER" -p"$MYSQL_PASS" "$DB_NAME" | gzip > "$LOCAL_BACKUP_DIR/$DB_NAME-$DATE.sql.gz"

if [ $? -eq 0 ]; then
  echo "Database backup created successfully!"
  # Upload the backup to the network share
  smbclient "$REMOTE_SHARE" -U "$REMOTE_USER%$REMOTE_PASS" <(echo "put $LOCAL_BACKUP_DIR/$DB_NAME-$DATE.sql.gz")
  if [ $? -eq 0 ]; then
    echo "Backup uploaded to network share."
  else
    echo "Error uploading backup to network share."
  fi
else
  echo "Error creating database backup."
fi

# Remove backups older than 7 days
find "$LOCAL_BACKUP_DIR" -type f -name "*.sql.gz" -mtime +7 -delete

脚本运行时

Database backup created successfully!
Error uploading backup to network share.

跑步二甲基乙二醇

CIFS VFS: Error connecting to socket. Aborting operation.
[ 12.261732] CIFS VFS: cifs_mount failed w/return code = -101
[ 12.390929] CIFS VFS: Error connecting to socket. Aborting operation.
[ 12.391002] CIFS VFS: cifs_mount failed w/return code = -101

尝试安装网络共享时/etc/fstab没有错误:

//SERVER/FOLDER_BACKUP /mnt/FOLDER_GLPI cifs username=USER_NETWORK_SHARE,password=PASSWORD_NETWORKSHARE,uid=USER_ACCOUNT_LINUX,gid=GROUP_ACCOUNT_LINUX

在手册中

sudo mount -t cifs -o username=USER_NETWORK_SHARE,uid=USER_ACCOUNT_LINUX,gid=GROUP_ACCOUNT_LINUX //SERVER/FOLDER_BACKUP /mnt/folder_backup
[sudo] password for USER_ACCOUNT_LINUX:
Password for USER_NETWORK_SHARE@//SERVER/FOLDER_BACKUP

/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/cgroup type tmpfs (rw)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
none on /sys/fs/pstore type pstore (rw)
systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd)
gvfsd-fuse on /run/user/112/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=lightdm)
//SERVER/FOLDER_BACKUP on /mnt/folder_backup type cifs (rw)

感谢您的帮助和贡献。

相关内容