Skip to content

Storage server

In this article

Information

General approaches to backups are described in Do-It-Yourself Backups, and moving data between servers in Migrating Data to a New 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.

The setup consists of two parts: steps 1-3 are performed on the storage server (it will be the NFS server), steps 4-7 on the client server that will mount the storage as a network folder. In the examples, 192.168.1.1 is the storage server address and 192.168.1.0/24 is the subnet allowed to connect.

  1. On the storage server, install the NFS server.

    Ubuntu / Debian:

    sudo apt install nfs-kernel-server
    

    CentOS 7 / AlmaLinux / Rocky Linux (use yum instead of dnf in CentOS 7):

    sudo dnf install nfs-utils
    sudo systemctl enable --now nfs-server
    
  2. On the storage server, configure directory exports. Specify the shared directories in the /etc/exports configuration file:

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

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

    Attention

    Do not open the export to the entire Internet: specify a particular client IP address or subnet. The no_root_squash option (full root privileges of the client on the exported directory) reduces security - use it only if it is really necessary.

  3. On the storage server, apply the settings:

    sudo exportfs -ra
    sudo systemctl restart nfs-kernel-server   # Ubuntu / Debian
    sudo systemctl restart nfs-server          # CentOS / AlmaLinux / Rocky Linux
    
  4. On the client server, install the NFS client utilities and create a mount point:

    sudo apt install nfs-common    # Ubuntu / Debian
    sudo dnf install nfs-utils     # AlmaLinux / Rocky Linux (yum in CentOS 7)
    sudo mkdir -p /mnt/nfs
    
  5. On the client server, mount the share:

    sudo mount 192.168.1.1:/data /mnt/nfs
    
  6. On the client server, configure automatic mounting on boot. Add this line to /etc/fstab (the _netdev option indicates that the network is required for mounting, nofail keeps the boot from stopping if the storage is unavailable):

    192.168.1.1:/data /mnt/nfs nfs defaults,_netdev,nofail 0 0
    

    You can use this command to check space usage:

    df -h /mnt/nfs
    
  7. To configure automatic backup of the client's data to the network folder using the rsync utility, add the appropriate command to crontab (cron settings file). For example, daily copying of the /var/www directory at 01:00:

    0 1 * * * rsync -a /var/www /mnt/nfs/backup/
    

    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              # Ubuntu / Debian
    sudo dnf install samba samba-client           # AlmaLinux / Rocky Linux (yum in CentOS 7)
    
  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
    

    Attention

    The guest ok = yes parameter opens the folder without a password. If the storage server is accessible from the Internet, remove it (or set guest ok = no) and restrict access to the SMB ports (445/TCP) with a firewall to your own IP addresses only. To log in with a user name and password, add a Samba user: sudo smbpasswd -a username (the user must exist in the system).

  4. Restart the Samba service:

    sudo systemctl restart smbd    # Ubuntu / Debian
    sudo systemctl restart smb     # CentOS / AlmaLinux / Rocky Linux
    
  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. If a separate disk is used for storing data on the storage server, you can mount it to the shared folder directory (the command is run on the storage server):

    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 MySQL/MariaDB database to the shared folder (the command is run on the Linux server where the database runs and where the /mnt/share directory is available):

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

    The mysqldump utility works only with MySQL and MariaDB. For Microsoft SQL Server, you can save a backup to the network folder with SQL Server itself, for example with a T-SQL command (the SQL Server service account must have write permissions for the folder):

    BACKUP DATABASE mydb TO DISK = '\\192.168.1.1\share\mydb.bak'
    

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.
  • Supports data compression during transfer (zlib, and in newer versions also zstd and lz4).
  • 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. CentOS 7 uses the yum package manager, while AlmaLinux / Rocky Linux and CentOS 8 use dnf.

  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 ed25519
    

    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 transferred in compressed form to the /backup/data directory of 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 data is transferred over the network in compressed form, and the files are stored on the server in their original form. Before overwriting or deleting existing files, rsync saves their previous versions with the ~ suffix (you can change the suffix with the --suffix parameter, and use --backup-dir to keep old versions in a separate directory).

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.

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×