| Both sides previous revision Previous revision Next revision | Previous revision |
| store_games_on_a_nas [2022/01/22 22:31] – grandmabetty | store_games_on_a_nas [2024/01/29 20:17] (current) – instructions for mounting network-based /userdata folders that are dependent on an established VPN or Tailscale connection cs |
|---|
| ====== Store games on a NAS ====== | ====== Store games on a NAS ====== |
| | |
| Instead of using the internal storage or an external USB key/hard drive to store your userdata (games, saves, configuration, etc.), you can use a NAS (Network Attached Storage) instead. | Instead of using the internal storage or an external USB key/hard drive to store your userdata (games, saves, configuration, etc.), you can use a NAS (Network Attached Storage) instead. |
| Of course you can also use your NAS as a backup target for all of your userdata and games for desaster recovery of your Batocera system as described below, just in case of...well...you name it. | |
| | Recommended watching: [[https://www.youtube.com/watch?v=w0tVE24Wmh4|Batocera Nation's advanced features volume 4.]] |
| | |
| | <WRAP center round important> |
| | Batocera repeatedly checks for a network connection on boot, and if none is present then it will automatically fall back to using internal storage. It is not possible to switch the location of your userdata without rebooting. If using NAS on a device which has a switch to turn on or off Wi-Fi, keep this fact in mind, as turning off the Wi-Fi will effectively wipe the userdata folder from Batocera's perspective. |
| | |
| | In general, if using Batocera on a portable device it's not recommended to use a local NAS for its storage anyway due to the instability of its Wi-Fi. [[:syncthing|Syncthing]] offers a much more secure method of syncing data between portable devices. |
| | </WRAP> |
| |
| ===== Syntax ===== | ===== Syntax ===== |
| | |
| You will need to replace the ''sharedevice=INTERNAL'' line with ''sharedevice=NETWORK'' inside ''batocera-boot.conf''. This file is on the [[:edit_boot_partition|boot partition]] of the Batocera system. If on a removable drive, you can edit it from any computer as it is in a readable FAT32 file system (don't use Windows Notepad). | You will need to replace the ''sharedevice=INTERNAL'' line with ''sharedevice=NETWORK'' inside ''batocera-boot.conf''. This file is on the [[:edit_boot_partition|boot partition]] of the Batocera system. If on a removable drive, you can edit it from any computer as it is in a readable FAT32 file system (don't use Windows Notepad). |
| |
| <WRAP center round tip 60%> | <WRAP center round tip> |
| You can tell if you have successfully done this as the **Storage Device** in **Main Menu** > **System Settings** will be blank! But that could also mean you've entered an invalid entry to ''sharedevice''... | You can tell if you have successfully done this as the **Storage Device** in **Main Menu** > **System Settings** will be blank! But that could also mean you've entered an invalid entry to ''sharedevice''... |
| </WRAP> | </WRAP> |
| |
| There are the pre-defined keywords you can use: | There are the pre-defined keywords you can use: |
| * For the whole user data directory, ''SHARE'' | |
| * For the roms directory, ''ROMS'' | ^ Keyword ^ Description ^ |
| * For the bios directory, ''BIOS'' | | ''SHARE'' | For the whole user data directory. | |
| * For the saves directory, ''SAVES'' | | ''ROMS'' | For the ''roms'' directory. | |
| * For custom menu background music, ''MUSIC'' | | ''BIOS'' | For the ''bios'' directory. | |
| * For custom bezels, ''DECORATIONS'' | | ''SAVES'' | For the ''saves'' directory. | |
| * For screenshots taken in game or with ''batocera-screenshot'', ''SCREENSHOTS'' | | ''MUSIC'' | For custom menu background music. | |
| * For themes, ''THEMES'' | | ''DECORATIONS'' | For custom bezels. | |
| * For cheats databases, ''CHEATS'' | | ''SCREENSHOTS'' | For screenshots taken in game or with ''batocera-screenshot''. | |
| * For sounds, ''SOUNDS'' (v32 and above) | | ''THEMES'' | For themes. | |
| * For magazine and videos, ''LIBRARY'' | | ''CHEATS'' | For cheat databases. | |
| * For the boot splash, ''SPLASH'' | | ''SOUNDS'' | For sounds (**v32** and above). | |
| | | ''LIBRARY'' | For magazine and videos. | |
| | | ''SPLASH'' | For the boot splash. | |
| |
| You can add any combination of the above (except ''SHARE'' as that includes everything) by adding additional lines. | You can add any combination of the above (except ''SHARE'' as that includes everything) by adding additional lines. |
| |
| <WRAP center round info 60%> | <WRAP center round info> |
| If you map only certain directories to your NAS, Batocera will search the internal storage for the remaining directories. | If you map only certain directories to your NAS, Batocera will search the internal storage for the remaining directories. |
| </WRAP> | </WRAP> |
| |
| ''%%@[IP-address]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' | ==== For Samba ==== |
| | |
| | ''%%@[IP-address/hostname]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' |
| |
| Then add the @ symbol, the IP address/hostname of the device with the share, the : character, the name of the share followed by a /, then the path to the directory (using Unix syntax / instead of \), another : character and then any additional options required for the share separated by a comma (,) (guest shares need only '':guest'' as an option, password protected shares need '':username=[your-username],password=[your-password]''). Syntax: | Then add the @ symbol, the IP address/hostname of the device with the share, the : character, the name of the share followed by a /, then the path to the directory (using Unix syntax / instead of \), another : character and then any additional options required for the share separated by a comma (,) (guest shares need only '':guest'' as an option, password protected shares need '':username=[your-username],password=[your-password]''). Syntax: |
| |
| ''%%sharenetwork_[smb-or-nfs][0-9]=[keyword]@[IP-address]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' | ''%%sharenetwork_[smb-or-nfs][0-9]=[keyword]@[IP-address/hostname]:[share-name]/[path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' |
| |
| Examples below. | ==== For NFS ==== |
| |
| <WRAP center round important 60%> | ''%%@[IP-address]:[/absolute/path/to/directory]:[option1-name]=[option1-value],[option2-name]=[option2-value],[etc.]%%'' |
| | |
| | Examples are [[#samba/windows_share_examples|below]]. If you don't know the exact address to your share already, check the [[#discover_network_share_names|discover network share names section below]]. |
| | |
| | <WRAP center round important> |
| If Batocera fails to connect to the network at boot, it will wait approximately one minute retrying to connect before falling back to internal storage. | If Batocera fails to connect to the network at boot, it will wait approximately one minute retrying to connect before falling back to internal storage. |
| </WRAP> | </WRAP> |
| |
| ===== Samba/Windows share examples ===== | ===== Samba/Windows share examples ===== |
| | |
| Windows shares can use identification or a guest account to connect. | Windows shares can use identification or a guest account to connect. |
| |
| |
| === The whole user data directory on the NAS === | === The whole user data directory on the NAS === |
| | |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_smb1=SHARE@192.168.0.1:Documents/batocera:guest | sharenetwork_smb1=SHARE@192.168.0.1:Documents/batocera:guest |
| </code> | </code> |
| === Only the roms directory on the NAS === | |
| | === Only the ROMs directory on the NAS === |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest | sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest |
| </code> | </code> |
| === Only the roms directory on the NAS with CIFS authentication === | |
| | === Only the ROMs directory on the NAS with CIFS authentication === |
| | |
| | <WRAP center round important> |
| | Unless you really know what you're doing, it is ill-advised to set up the NAS with a username and password for your ROMs, saves and system folders. This can interfere with Batocera's access to executable bits, leading to the same problems that the NTFS filesystem has. |
| | |
| | It is recommended however to use authentication for your NAS in general, it's possible to create an additional share that only shares the ROMs folder with guest access for example. |
| | |
| | If your NAS was already using NTFS then this limitation is already in affect, thus it would be no different to using authentication anyway. |
| | </WRAP> |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:username=john,password=wayne | sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:username=john,password=wayne |
| </code> | </code> |
| === The roms, saves and bios directories on the NAS === | |
| | === The ROMs, saves and BIOS directories on the NAS === |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest | sharenetwork_smb1=ROMS@192.168.0.1:Documents/batocera/roms:guest |
| sharenetwork_smb2=SAVES@192.168.0.1:Documents/batocera/saves:guest | sharenetwork_smb2=SAVES@192.168.0.1:Documents/batocera/saves:guest |
| sharenetwork_smb3=BIOS@192.168.0.1:Documents/batocera/bios:guest | sharenetwork_smb3=BIOS@192.168.0.1:Documents/batocera/bios:guest |
| </code> | </code> |
| |
| === Specific SMB version options === | === Specific SMB version options === |
| | |
| In several cases, **you need to add SMB options**, for instance if you NAS requires a specific CIFS version: | In several cases, **you need to add SMB options**, for instance if you NAS requires a specific CIFS version: |
| |
| |
| === The whole user data directory on the NAS === | === The whole user data directory on the NAS === |
| | |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_nfs1=SHARE@192.168.0.1:/mnt/Documents/batocera | sharenetwork_nfs1=SHARE@192.168.0.1:/mnt/Documents/batocera |
| </code> | </code> |
| === Only the roms directory on the NAS, with a specific NFS version === | |
| | === Only the ROMs directory on the NAS, with a specific NFS version === |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms:vers=4 | sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms:vers=4 |
| </code> | </code> |
| === The roms, saves and bios directories on the NAS === | |
| | === The ROMs, saves and BIOS directories on the NAS === |
| <code> | <code> |
| sharedevice=NETWORK | sharedevice=NETWORK |
| sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms | sharenetwork_nfs1=ROMS@192.168.0.1:/mnt/Documents/batocera/roms |
| sharenetwork_nfs2=SAVES@192.168.0.1:/mnt/Documents/batocera/saves | sharenetwork_nfs2=SAVES@192.168.0.1:/mnt/Documents/batocera/saves |
| sharenetwork_nfs3=BIOS@192.168.0.1:/mnt/Documents/batocera/bios | sharenetwork_nfs3=BIOS@192.168.0.1:/mnt/Documents/batocera/bios |
| </code> | </code> |
| |
| ===== Advanced ===== | ===== Mounting network shares behind a VPN or Tailscale network ===== |
| | === Background === |
| | Mounting a shared folder on a server that requires a VPN or Tailscale connection to be established first is troublesome due to the Batocera boot initialization process. While Batocera does provide [[:launch_a_script|various options]] for you to execute a custom script throughout the boot process, none of them are suitable due to several factors. The setup procedure in the [[:vpn_client|VPN/Tailscale documentation]] is great for setting up things like multiplayer, but too late for mounting Batocera core folders. |
| |
| === Troubleshooting === | __Basic boot process flow:__\\ |
| | 1. /boot/boot-custom.sh - At this stage, the system's network has not been initialized yet, therefore a VPN or Tailscale connection cannot be established.\\ |
| | 2. /etc/init.d/S07network - This is where the network is initialized.\\ |
| | 3. /etc/init.d/S11share - This is where the /userdata is initialized.\\ |
| | 4. /boot/postshare.sh - Executed right after /userdata initialization completed. By this point it is too late, and any attempts to mount a VPN/Tailscale network share will fail because those services haven't been initialized yet.\\ |
| | 5. /userdata/system/custom.sh - This script is the suggested place for VPN/Tailscale initialization according to the docs, but it's also past the /userdata mounting stage.\\ |
| |
| Make sure you escape special characters in your CIFS passwords if you have some. To escape a character, put a \ in front of it. To escape a \ itself, use %%\\%%. | From the above, we can see that the VPN/Tailscale client will need to be initialized somewhere between steps 2 and 3. |
| |
| For troubleshooting purposes, you have ''/tmp/mountNetwork.log'' and ''/tmp/mountNetwork.err'' that will give you some insights on the mount failures if needed. | === Workaround === |
| | There is a [[:store_games_on_a_nas#samba_windows_manually_mounted_shares|sharenetwork_cmd# feature]] that allows you to craft a custom mounting command, however, since it accepts any arbitrary shell command we can repurpose it to initialize our VPN/Tailscale client. |
| |
| === Samba/Windows manually mounted shares === | First, setup and test the VPN/Tailscale client according to the [[:vpn_client|docs]]. Once you have successfully confirmed that everything is working, disable ''custom.sh'' or comment out the lines relevant to VPN/Tailscale. Those clients are going to be initialized elsewhere. |
| It is possible to map individual folders with ''sharenetwork_cmd#'' if you are familiar with [[https://linux.die.net/man/8/mount.cifs|standard Linux network storage mounting]]. Examples of mapping other directories via sharenetwork_cmd: | |
| |
| | The final result of my configuration looks something like the below. Note that in my example, I am using Tailscale and mounting NFS folders, although this should be adaptable for any combination of VPN/Tailscale and SMB/NFS. Also, in my example, I am incorporating an [[:vpn_client#my_vpn_works_fine_on_my_pc_but_not_on_my_raspberry_pi_other_sbc|ARM-build fix]] where the /dev/net folder needs to be created in addition to a "sleep 2s" command because I have observed that the Tailscale daemon sometimes does not finish initializing before the Tailscale client asks it to bring up the network. Adjust these items according to your setup. |
| <code> | <code> |
| sharenetwork_cmd1=mount.cifs -o guest //192.168.0.1/Documents/batocera/music /userdata/music | sharedevice=NETWORK |
| sharenetwork_cmd2=mount.cifs -o guest //192.168.0.1/Documents/batocera/cheats /userdata/cheats | sharenetwork_cmd1=eval if [ ! -d /dev/net ]; then mkdir -p /dev/net; mknod /dev/net/tun c 10 200; chmod 600 /dev/net/tun; fi && /userdata/tailscale/tailscaled -state /userdata/tailscale/state > /userdata/tailscale/tailscaled.log 2>&1 & sleep 2s; /userdata/tailscale/tailscale up --accept-routes |
| sharenetwork_cmd3=mount.cifs -o guest //192.168.0.1/Documents/batocera/screenshots /userdata/screenshots | sharenetwork_nfs1=ROMS@100.0.0.1:/mnt/Documents/batocera/roms |
| sharenetwork_cmd4=mount.cifs -o guest //192.168.0.1/Documents/batocera/themes /userdata/themes | sharenetwork_nfs2=SAVES@100.0.0.1:/mnt/Documents/batocera/saves |
| | sharenetwork_nfs3=BIOS@100.0.0.1:/mnt/Documents/batocera/bios |
| </code> | </code> |
| |
| This will only work if ''sharedevice=NETWORK''. You can also use this to just mount anything with acceptable bash commands, including folders from local drives, etc. | ===== Advanced ===== |
| |
| <WRAP center round tip 60%> | === Troubleshooting === |
| These will appear as if though they are local to the drive, so keep that in mind when troubleshooting in the future! | |
| </WRAP> | |
| |
| === NFS and root permissions === | Make sure you escape special characters in your CIFS passwords if you have some. To escape a character, put a \ in front of it. To escape a \ itself, use %%\\%%. |
| Batocera has a unique ''root'' user, so all files accessed on the share are from the ''root'' user, which can conflict with how your other NFS clients access files. | |
| You should check how the file permissions are declared on your NFS server, but a common way to make sure your file permissions are managed correctly is to map the file rights to the UID of the user that will access these files locally. Typically, if your NFS shares are defined in ''/etc/exports'' and you want to give access to a user with UID/GID of 1000, you can make it with: | |
| <code> | |
| /media/games/batocera 192.168.0.1(rw,sync,all_squash,anonuid=1000,anongid=1000,no_subtree_check) | |
| </code> | |
| |
| ==== Backup your data to a NAS ==== | For troubleshooting purposes, you have ''/tmp/mountNetwork.log'' and ''/tmp/mountNetwork.err'' that will give you some insights on the mount failures if needed. |
| |
| In this example we will cover how to **automatically** backup the most important data folder ''/userdata'', which contains all important (custom) configurations and games of your Batocera system so that in case of emergency you will have all your data in a recoverable state. | === Discover network share names === |
| |
| === Synology NAS example === | If you haven't yet used the network share with other devices and aren't confident of the name of the share itself (very common for NASes to report a false path to go to to access their data) then you can "see" the available network shares from Batocera's [[:built_file_manager|file manager]]. On the system list, press ''[F1]'' to open it. Then, in the menu at the top of the screen, navigate to **Go** -> **Network**. The names of the available network shares (along with Batocera's own network share) will be shown: |
| |
| <WRAP center round tip 60%> | {{:screenshot_from_2022-01-28_14_54_26.png|}} |
| This tutorial assumes you have already set a static IP address for your Synology NAS on the according LAN interface and a static IP address for your Batocera system. To set a static IP address for your Batocera system it is best to configure it based on your Batocera system's MAC address on your network's DHCP server (mostly your router) as you cannot set a static IP address via the Batocera GUI (yet). | |
| Also, for automation purposes, you will need to have at least one (if you have multiple) of your Synology's network interface(s) within the same Layer 2 network subnet as your Batocera system and your Batocera system has to be [[wake_on_lan|Wake on LAN (WoL)]] capable. | |
| </WRAP> | |
| |
| For this tutorial you will need to enable the following services on your Synology NAS via the Synology DSM web GUI as follows: | This can be used to confirm that your Batocera machine can at least see the NAS. You may want to note down these names. You will not be able to access any shares from this menu, however. |
| * **SMB** → Navigate to ''Control Panel'' → ''File Services'' → ''SMB'' → Check ''Enable SMB service'': \\ {{:useanasbackup01.png?300|Enable SMB}} | |
| * **rsync** → Navigate to ''Control Panel'' → ''File Services'' → ''rsync'' → Check ''Enable rsync service'' and for ''SSH encryption port:'' set the value ''22'': \\ {{:useanasbackup02.png?600|Enable rsync}} | |
| * **SSH** → Navigate to ''Control Panel'' → ''Terminal & SNMP'' → Check ''Enable SSH service'' and for ''Port:'' set the value ''22'': \\ {{:useanasbackup05.png?500|Enable SSH}} | |
| |
| <WRAP center round tip 60%> | === Discover network share paths === |
| You don't have to worry if you are already using port 22 for default SSH encrypted connections, its functionality will not be interferred/disrupted in any way! | |
| </WRAP> | |
| |
| Next, you will need to [[https://kb.synology.com/en-us/DSM/help/DSM/AdminCenter/file_user_create?version=6|create a user]] (standard local user without administrative privileges) for backup purposes on your Synology NAS. For this tutorial we will name the user ''backup''. | Kodi can be used to see //and// access network shares. You may need [[#discover_network_share_names|your network share's name]] in order to do this. Open Kodi, then navigate to **Files** (a.k.a. **Enter files section**) -> **Files** -> **Add media...** (by default, **Add videos...**) -> **Browse** -> **Add network location...**. |
| |
| Next, you will need to [[https://kb.synology.com/en-us/DSM/help/DSM/AdminCenter/file_share_create?version=6|create a shared folder]] where your Batocera data can be stored to. For this tutorial we will name the shared folder ''batoceraBackup''. You have to set //read/write// permissions on that shared folder for the specific user you have created before: | {{:screenshot-2022.01.28-15h16.44.png?720|}} {{:screenshot-2022.01.28-15h16.51.png?720|}} {{:screenshot-2022.01.28-15h16.56.png?720|}} {{:screenshot-2022.01.28-15h17.01.png?720|}} |
| |
| {{:useanasbackup03.png?900|User permissions}} | From here, enter the network share name (and your username and password if you don't have guest/anonymous access enabled on your NAS): |
| |
| Next, you will need to [[https://kb.synology.com/en-us/DSM/help/DSM/AdminCenter/connection_security_firewall?version=6|create a firewall rule]] on your Synology NAS so that your Batocera system can send its data over the network to the Synology NAS. The rule must allow the following two services: | {{:screenshot-2022.01.28-15h17.57.png?720|}} |
| * ''Windows file server'' | |
| * ''Encrypted terminal service (includes encrypted rsync and SFTP)'' | |
| In addition it is also strongly(!) recommended to limit the firewall rule to allow only the static IP address of your Batocera system: | |
| |
| {{:useanasbackup04.png?1000|Firewall rule(s)}} | <WRAP center round tip> |
| | In the case that you don't know the name of the networked device (or one isn't available because your router has hostnames disabled/a very strict firewall) it is still possible to discover the IP address of the networked device from here. |
| |
| Now [[https://wiki.batocera.org/access_the_batocera_via_ssh|SSH]] into your Batocera system and execute the following command to create a custom ''scripts'' folder: | Instead of going to **Add network location...**, instead go to **Zeroconf browser**. You will be shown a list of all devices. Select the one you wish to use, and if a username/password is required you will be prompted for one. After that, continue following the steps as usual, replacing the share name with the IP address you will be shown. |
| <code>mkdir -p /userdata/scripts</code> | |
| | |
| <WRAP center round tip 60%> | |
| On the following steps we will cover on how to create three scripts here: | |
| * ''romsBackup.sh'' → Which will backup your ''/userdata/roms'' folder. | |
| * ''userdataBackup.sh'' → Which will backup your ''/userdata'' folder, excluding the ''/userdata/roms'' folder as it //may// take a very long time to execute, depending on how many games you have to copy over. This way you can backup the rest of your userdata independent from your games. | |
| * ''systemBackup.sh'' → Which will only execute the two scripts ''romsBackup.sh'' and ''userdataBackup.sh''. | |
| We are separating the first two scripts instead of putting them in a single script so you can execute them manually whenever you want to, indepented from the automation steps we are covering below. The third script is exactly for those automation steps. | |
| </WRAP> | </WRAP> |
| |
| <WRAP center round important 60%> | Your share will be added to the list of browseable devices, navigate to it (in this example, ''%%smb://RASPBERRYPI%%'') and then navigate to the folder you intend to use for Batocera. |
| **Beware:** The ''--delete'' option within the following two scripts ''romsBackup.sh'' and ''userdataBackup.sh'' does delete every file on the target side which is not available on the source side. We are using this option due to keep the target side consistent with the source side (for example if you have deleted some games on the source side and you want them being deleted on the target side too). If you don't want this to happen then just remove the ''--delete'' option on both scripts! | |
| </WRAP> | |
| |
| Now create the following script file: | {{:screenshot-2022.01.28-15h18.17.png?720|}} {{:screenshot-2022.01.28-15h18.23.png?720|}} {{:screenshot-2022.01.28-15h18.42.png?720|}} |
| <code>nano /userdata/scripts/romsBackup.sh</code> | |
| And paste the following content (replace ''<your_password>'' with the according //backup// user its user password and ''<Synology_NAS_IP_address>'' with the static IP address of your Synology NAS): | |
| <code> | |
| #!/bin/sh | |
| USER=backup | |
| PASS=<your_password> | |
| SHARE=//<Synology_NAS_IP_address>/batoceraBackup | |
| MOUNT_POINT=/tmp/tempMountFolder | |
| mkdir -p "$MOUNT_POINT" | |
| mount -t cifs -o username="$USER",password="$PASS" "$SHARE" "$MOUNT_POINT" | |
| rsync -Pav --delete -e ssh /userdata/roms "$MOUNT_POINT" | |
| cd /tmp | |
| umount -f "$MOUNT_POINT" | |
| exit 0 | |
| </code> | |
| Save the file and quit the editor. | |
| |
| Now create the following script file: | Note down the file path stated at the bottom of the window, this is the path that should be used when configuring your NAS. eg. Kodi's path ''%%smb://RASPBERRYPI/samsung1tb/Emulation/roms%%'' contains the share using the Samba (smb) protocol with the hostname ''RASPBERRYPI'' with the share name ''samsung1tb'' and the path being ''samsung1tb/Emulation/roms''. The correct configuration lines for ''batocera-boot.conf'' would be: |
| <code>nano /userdata/scripts/userdataBackup.sh</code> | |
| And paste the following content (replace ''<your_password>'' with the according //backup// user its user password and ''<Synology_NAS_IP_address>'' with the static IP address of your Synology NAS): | |
| <code> | |
| #!/bin/sh | |
| USER=backup | |
| PASS=<your_password> | |
| SHARE=//<Synology_NAS_IP_address>/batoceraBackup | |
| MOUNT_POINT=/tmp/tempMountFolder | |
| mkdir -p "$MOUNT_POINT" | |
| mount -t cifs -o username="$USER",password="$PASS" "$SHARE" "$MOUNT_POINT" | |
| cd "$MOUNT_POINT" | |
| tar cfv "$MOUNT_POINT"/batoceraBackup.tar /userdata --exclude=roms --exclude=saves/flatpak | |
| rm -rf ./batoceraBackup.tar | |
| cd /tmp | |
| umount -f "$MOUNT_POINT" | |
| exit 0 | |
| </code> | |
| Save the file and quit the editor. | |
| |
| Now create the following script file: | |
| <code>nano /userdata/scripts/systemBackup.sh</code> | |
| And paste the following content: | |
| <code> | <code> |
| #!/bin/sh | sharedevice=NETWORK |
| /userdata/scripts/romsBackup.sh | sharenetwork_smb1=ROMS@RASPBERRYPI:samsung1tb/Emulation/roms |
| /userdata/scripts/userdataBackup.sh | |
| shutdown -h now | |
| </code> | </code> |
| Save the file and quit the editor. | |
| |
| Now make all three scripts executable by executing: | === Samba/Windows manually mounted shares === |
| <code>chmod +x /userdata/scripts/*.sh</code> | |
| |
| Now let's do the automation part: | It is possible to map individual folders with ''sharenetwork_cmd#'' if you are familiar with [[https://linux.die.net/man/8/mount.cifs|standard Linux network storage mounting]]. Examples of mapping other directories via sharenetwork_cmd: |
| |
| [[https://kb.synology.com/en-global/DSM/tutorial/How_to_login_to_DSM_with_root_permission_via_SSH_Telnet|SSH]] with user ''root'' into your Synology NAS (Unfortunately you have to use a Synology user which is part of the ''administrators'' group, otherwise SSH access will be declined. To avoid any permission issues, we will user ''root'' here.). Then execute the following commands (replace ''<Batocera_IP_address>'' with the static IP address of your Batocera system): | <code> |
| <code>ssh-keygen</code> | sharenetwork_cmd1=mount.cifs -o guest //192.168.0.1/Documents/batocera/music /userdata/music |
| <code>cat ~/.ssh/id_rsa.pub | ssh root@<Batocera_IP_address> 'cat >> /userdata/system/ssh/authorized_keys'</code> | sharenetwork_cmd2=mount.cifs -o guest //192.168.0.1/Documents/batocera/cheats /userdata/cheats |
| Insert the Batocera ''root'' user's password (Default password: ''linux''). | sharenetwork_cmd3=mount.cifs -o guest //192.168.0.1/Documents/batocera/screenshots /userdata/screenshots |
| | sharenetwork_cmd4=mount.cifs -o guest //192.168.0.1/Documents/batocera/themes /userdata/themes |
| | </code> |
| |
| Now go back to the Synology DSM web GUI and create the according automation task: | This will only work if ''sharedevice=NETWORK''. You can also use this to just mount anything with acceptable bash commands, including folders from local drives, etc. |
| Navigate to ''Control Panel'' → ''Task Scheduler'' → ''Create'' → ''Scheduled Task'' → ''User-defined script'' → ''General'': For ''Task'' insert a custom task name (e.g. ''batoceraBackup'') and for ''user'' choose ''root'' → ''Schedule'': Configure a desired custom schedule → ''Task Settings'': For ''User-defined script'' insert the following (replace ''<Batocera_MAC_address>'' with the according MAC address of your Batocera system and ''<Synology_network_interface>'' with the according network interface name through which you want to send the magic packet to (the one which is within the same Layer 2 subnet as your Batocera system, e.g. ''eth0''): | |
| |
| <WRAP center round tip 60%> | <WRAP center round tip> |
| If your Synology NAS does have multiple network interfaces, to find out which network interface name you have to take, from Synology DSM web GUI navigate to: ''Control Panel'' → ''Info Center'' → ''Network''. All of the available network interfaces are listed here with all the unique network/subnet informations. ''LAN1'' is always ''eth0'', ''LAN2'' is always ''eth1'', ''LAN 3'' is always ''eth2'', etc.) | These will appear as if though they are local to the drive, so keep that in mind when troubleshooting in the future! |
| </WRAP> | </WRAP> |
| |
| <WRAP center round tip 60%> | === NFS and root permissions === |
| If your Batocera system takes longe than 30 seconds to boot up, feel free to increase the ''sleep'' variable to whatever value you think does fit the real boot time of your Batocera system. | |
| </WRAP> | Batocera has a unique ''root'' user, so all files accessed on the share are from the ''root'' user, which can conflict with how other NFS clients access files. You should check how the file permissions are declared on your NFS server. A common way to make sure your file permissions are managed correctly is to map the file rights to the UID of the user that will access these files locally. Typically, if your NFS shares are defined in ''/etc/exports'' and you want to give access to a user with UID/GID of 1000, you can make it with: |
| |
| <code> | <code> |
| #!/bin/sh | /media/games/batocera 192.168.0.1(rw,sync,all_squash,anonuid=1000,anongid=1000,no_subtree_check) |
| sudo synonet --wake <Batocera_MAC_address> <Synology_network_interface> | |
| sleep 30 | |
| ssh root@<Batocera_IP_address> sh ../scripts/systemBackup.sh | |
| </code> | </code> |
| Confirm by clicking on ''OK''. | |
| |
| That's it! Your scheduled backup automation should work now. | ===== Troubleshooting ===== |
| | |
| | Logs for share mounting specifically can be found at ''/tmp/mountDevicesOrNetwork.err'' after booting. If a network share is failing to be booted, Batocera will retry the connection a few times before falling back on internal storage. |
| |