Skip to content

Storage server

Using a storage server as a network drive/folder via NFS on Linux

Information

The Network File System (NFS) protocol is an application layer protocol that allows clients to access files on a remote server over a network as if they were local. NFS uses a client-server model where the server exports one or more directories and clients mount them on their file systems. The NFS protocol has features such as ease of configuration, cross-platform, transparent file access, data caching, scalability, fault tolerance and security, which together make it very suitable as a protocol for connecting to storage servers, allowing users from different operating systems to work with data on networked storage easily and efficiently.

To use a storage server as a network drive/folder via NFS on Linux, you need to

  1. Install the NFS server. Install the nfs-kernel-server and rpcbind packages:

    sudo apt install nfs-kernel-server rpcbind
    
  2. Configure directory exports. Specify the shared directories in the /etc/exports configuration file:

    /data 192.168.1.0/24(rw,sync,no_root_squash)
    

    This action allows read and write access to the /data directory from the specified subnet.

  3. Restart the NFS server with the command:

    sudo systemctl restart nfs-kernel-server
    
  4. Mount the local device:

    sudo mount 192.168.1.1:/data /mnt/nfs
    
  5. Configure automatic mounting on boot. Add this line to /etc/fstab:

    192.168.1.1:/data /mnt/nfs nfs defaults 0 0
    

    You can use this command to check space usage:

    df -h /mnt/nfs
    
  6. To configure automatic backup using the rsync utility, you need to add the appropriate command to crontab (cron settings file):

    0 1 * * * rsync -avz /mnt/nfs /backup/nfs
    
  7. To create a backup (dump) of a MySQL database, you can use the mysqldump utility:

    mysqldump -u root -p mydb > /mnt/nfs/dump.sql
    

    This command saves a full backup of the mydb database to the dump.sql file in the /mnt/nfs/dump.sql path. The -u parameter specifies the user name to connect to MySQL, -p prompts for a password. To create backups in automatic mode, you can configure this command to run on a schedule using the cron utility.

Use storage server as network drive/folder using Samba protocol on Windows OS

Information

Samba is freely distributed software that allows Linux/Unix and Windows systems to communicate on a network at the file and printer level. Samba implements the SMB/CIFS protocols used for file sharing in Windows. This makes it easy to organise file and printer sharing between Linux and Windows computers.

To use a storage server as a network drive/folder using the Samba protocol in Windows, you need to:

  1. Install the samba and smbclient packages on the storage server:

    sudo apt install samba smbclient
    
  2. Create a folder that will be open for network access, such as /mnt/share:

    sudo mkdir /mnt/share
    
  3. Add this folder to your samba configuration file:

    sudo nano /etc/samba/smb.conf
    

    Add to the end of the configuration file:

    [share]
       comment = Network Share
       path = /mnt/share
       browsable = yes
       guest ok = yes
       read only = no
       create mask = 0755
    

  4. Restart the Samba service:

    sudo service smbd restart
    
  5. On your local Windows device, open Explorer and select the Map network drive tab:

  6. Enter the path to the storage server and the Share network folder:

    You will then be prompted to enter credentials to connect to the server and complete the connection:

    If the connection is successful, the network folder will be visible in Explorer under Network locations:

    If you are experiencing problems working with a network folder due to a lack of permissions, you should check the permissions for working with the folder. You can do this using any graphical client for the SFTP and SCP protocols, such as WinSCP:

    Once the user has been given the necessary rights, the network folder will be writable.

  7. To mount the drive, use the command:

    sudo mount /dev/sdb1 /mnt/share
    
  8. To unmount:

    sudo umount /mnt/share 
    
  9. Use the df command to monitor the occupied space:

    df -h /mnt/share
    

  1. To copy data automatically, configure a job in crontab:

    0 0 * * * rsync -av /source/dir /mnt/share
    
  2. To back up a MSSQL database, use the command:

    mysqldump -u root -p mydb > /mnt/share/mssql_backup.sql
    

Using the storage server from the terminal using the Rsync and SCP utilities

Information

Rsync and SCP are command line utilities in Linux and other Unix-like systems for transferring files over a network. Using Rsync and SCP and other utilities to work with files on a remote storage server from the terminal allows you to perform many tasks:

  • Automate file transfer and synchronization between servers
  • Backup data on storage;
  • Centralize file storage and management;
  • Fast and flexible file manipulation without a graphical interface;
  • Scripting and batching of various data handling tasks.

Advantages of using Rsync over SCP and FTP:

  • Rsync is faster due to incremental file transfer, only changes are transferred;
  • Compression support and traffic savings;
  • Ability to flexibly configure synchronization parameters;
  • Support for resuming interrupted file transfers;
  • Remote directory mirroring.

For backup, synchronisation and automation tasks, Rsync is therefore often the optimal solution and is preferred by system administrators. It is a powerful and flexible tool for managing files on remote storage.

Rsync

Rsync is a utility for synchronizing files and directories between nodes on a network. Features of Rsync:

  • Synchronizes the entire directory structure as well as individual files.
  • When resynchronizing, it only transfers changed parts of files.
  • Uses the Deflate data compression algorithm and the zlib library.
  • Uses channel bandwidth sparingly.
  • Replicates file permissions.
  • Does not require root privileges to operate.
  • Suitable for backup and recovery.

Note

The convention used in this manual is user@storage-server. When working with a remote server, an SSH connection requires a user name, such as root, and the IP address of the server. Therefore, when entering the commands in the examples below, you must enter your credentials in user@IP-address format, e.g. [email protected]. The IP address of the server can be found in the Network tab of Invapi:

How to use Rsync to work with files on a storage server from the Terminal:

Note

In our example, we use the apt package manager designed for use in Debian/Ubuntu distributions. For Red Hat based distributions, the yum package manager is used.

  1. Install Rsync on the local machine:

    sudo apt install rsync
    
  2. Connect to the storage server. For SSH connection it is better to configure key authorization. You can use the command to generate an SSH key:

    ssh-keygen -t rsa
    

    Then copy the key to the storage server:

    ssh-copy-id user@storage-server
    
  3. Synchronize directories. For example, to synchronize the /data directory with the storage server:

    rsync -avz /data user@storage-server:/backup/data
    

    Options decryption:

    • avz:
      • a - archive mode. Stores symbolic links, owners, groups, permissions and timestamps;
      • v - increase verbosity. Displays messages about the file copying process;
      • z - compress file data during the transfer to reduce traffic;
    • /data - local source directory;
    • user@storage-server:/backup/data - destination folder on the remote server.

    This command copies the /data directory from the local computer to the remote storage server in archive mode. The process is accompanied by detailed output and the data is compressed into the /backup/data directory for the user user.

    Copying is performed over the network with all file attributes intact.

  4. For a complete mirroring of a directory, you can use the optional --delete option, which is necessary to delete unnecessary files:

    rsync -avz --delete /data user@storage-server:/backup/data
    

    Options decryption:

    • avz:
      • a - archive mode. Stores symbolic links, owners, groups, permissions and timestamps;
      • v - increase verbosity. Displays messages about the file copying process;
      • z - compress file data during the transfer to reduce traffic;
    • -delete - deletes files in the destination directory /backup/data that are not in the source directory /data; /data - local source directory; user@storage-server:/backup/data - destination folder on the remote server.
  5. Perform a backup using the --backup option:

    rsync -avz --backup --delete /data user@storage-server:/backup/data
    

    Running this command will save old versions of the modified files. For example

    rsync --archive --backup --compress /home/user/documents user@storage-server:/backup/documents
    

    This command creates an archived copy of the /home/user/documents directory on the storage server in /backup/documents. The files are copied in compressed form. The copy will backup existing files with the extension .1.

SCP and FTP: file transfer protocols

Several data transfer protocols can be used to work with files on a remote storage server from the terminal.

SCP (Secure Copy)

SCP allows encrypted copying of files between hosts. To copy a file to a storage server, use the command:

scp file.txt user@storage-server:/path/to/destination 

To download a file from the server:

scp user@storage-server:/path/to/file /local/path

FTP (File Transfer Protocol)

To connect via FTP, use the `ftp' command:

ftp storage-server

Upload the file to the server:

put file.txt

Download the file:

get file.txt

Using the storage server with SFTP and FTP clients

Storage servers are used to store and share data. But to take advantage of their benefits, you need convenient and secure access to the files stored on them.

  • SFTP (Secure File Transfer Protocol) and FTP (File Transfer Protocol) are protocols used to transfer files between computers over a network.
  • SFTP is an extension of the SSH protocol and provides encrypted and secure file transfer. FTP uses clear text without encryption. SFTP is preferred when confidentiality and data integrity are required.
  • SFTP and FTP clients are programs that allow a user to connect to SFTP or FTP servers and manage files on those servers. Popular SFTP clients include FileZilla, WinSCP, CyberDuck. Popular FTP clients: FileZilla, SmartFTP, WinSCP.

Note

The main difference between SFTP and FTP is the use of encryption. SFTP encrypts all connections, ensuring data security. FTP transmits data in clear text, leaving it open to interception and modification. In addition, SFTP uses SSH for authentication, whereas FTP uses separate passwords.

WinSCP

To use WinSCP in Windows, you need to:

  1. Download and install the WinSCP client on a local Windows device.

  2. Launch WinSCP. In the Login window, enter the following details:

    • Host name: remote server IP address or domain name;
    • Port number: 22;
    • User name: server login;
    • Password: server password.

  3. Press Login to connect to the server.

  4. The left pane contains files on the local device, the right pane contains files on the remote server:

  5. To copy a file from the computer to the server - drag it with the mouse from the left pane to the right pane.

  6. To transfer files between the server and the local device, simply drag them from one panel to the other.

  7. To finish your work, click Close or close the program.

  8. All file copies are encrypted using the SFTP protocol. If you wish, you can select another protocol for the connection.

FileZilla in Linux

To use FileZilla on Linux, you need to:

  1. Install FileZilla from the repositories of the Linux distribution you are using. For example, in Ubuntu:

    sudo apt install filezilla
    
  2. Launch FileZilla. Enter the details in the Quickconnect bar:

    • Host: protocol (SFTP) and IP address or domain of the storage server (e.g. sftp://31.45.10.34);
    • Port: 22;
    • Username: server login;
    • Password: server password.
  3. Press Quickconnect. When the connection is successful, the home directory of the local device is displayed on the left.

  4. To transfer files between the server and the local device, simply drag and drop them from one panel to the other.

  5. Press the Disconnect button to exit.