HOW-TO Install a Reliable Base Server on Raspberry Pi
Setting up the basic items I use on every server installation.
Start with a headless Raspberry Pi installation as per this HOW-TO: http://tinab.blog/how-to-headless-pi-easy-setup
Once on an ethernet connection, disable WiFi & set a hostname
sudo nano /boot/firmware/config.txt
add the following
dtoverlay=disable-wifi
Set an appropriate hostname in raspi-config
sudo raspi-config
Update the system
sudo apt update && sudo apt -y upgrade
sudo apt full-upgrade
Install Samba and create a share
sudo apt install samba
sudo smbpasswd -a <username>
mkdir smb_transfer_folder
sudo nano /etc/samba/smb.conf
add the following at the bottom
[smb_transfer_folder]
path=/home/<username>/smb_transfer_folder
writeable=Yes
create mask=0777
directory mask=0777
public=no
then restart the service
sudo systemctl restart smbd
Install and configure network monitor
sudo apt install nmon
mkdir /home/<username>/nmon
sudo nano /etc/crontab
Add the following to the block of tasks to execute, replace <hostname> with the name of this system
02 0 * * * root nmon -s 240 -c 360 -F /home/<username>/nmon/<hostname>_$(date +"%y%m%d_%H%M".nmon)
Install, configure and schedule a job for iDrive backup
wget https://www.idrivedownloads.com/downloads/linux/download-for-linux/linux-bin/idriveforlinux.bin
chmod a+x idriveforlinux.bin
export LD_LIBRARY_PATH=/opt/IDriveForLinux/bin/Idrivelib/dependencies/python/lib:$LD_LIBRARY_PATH
sudo nano ~/.bashrc
Add the following to the end of the file
LD_LIBRARY_PATH=/opt/IDriveForLinux/bin/Idrivelib/dependencies/python/lib:$LD_LIBRARY_PATH
Install the client and create an initial general-use backup folder
./idriveforlinux.bin --install
mkdir /home/<username>/backups
Next, edit the backupset file using Vi. Once opened press <ENTER> then ” i ” to enter “insert” mode
/opt/IDriveForLinux/bin/idrive -e
add a single line, replacing <username> with the username to be backed up
/home/<username>/backups/
to exit, save and continue press <ESCAPE> then type
:wq!
Press <ENTER> and once exited select ” n ” to edit no more files. If Vi proves troublesome note that ” i ” enters insert mode, <ESCAPE> returns to command mode, and ” dd ” deletes the current line
Ensure the backup runs successfully and uploads successfully
touch /home/<username>/backups/testing.txt
/opt/IDriveForLinux/bin/idrive -b
Login and look for the “testing.txt” file. If it isn’t there (and failed) then execute the following and try again
export LD_LIBRARY_PATH=/opt/IDriveForLinux/bin/Idrivelib/dependencies/python/lib:$LD_LIBRARY_PATH
/opt/IDriveForLinux/bin/idrive --account-setting
Finally, schedule a daily backup by executing the following and responding to the prompts
/opt/IDriveForLinux/bin/idrive -s
the installer can be removed if desired
rm -rf /home/<username>/idriveforlinux.bin
Create scripts to locally backup any required data to the standard backup folder so iDrive takes a copy with the above scheduled job
The following will create a copy of relevant files in the /home/<username>/backups folder on a daily basis so that iDrive creates an online backup. It also logs its activity and takes a copy of itself.
mkdir /home/<username>/backups/scripts
mkdir /home/<username>/backups/archive
sudo touch /home/<username>/backups/scripts/daily_base_backups.sh
sudo chmod 755 /home/<username>/backups/scripts/daily_base_backups.sh
sudo nano /etc/crontab
Add the following line to the block of scheduled tasks
43 2 * * * root /home/<username>/backups/scripts/daily_base_backups.sh
Then edit the script
sudo nano /home/user/backups/scripts/daily_base_backups.sh
and copy the following in before Ctrl+X, yes, <ENTER> to exit and save (replace <username> on line 3 with the username used throughout, above.
#!/bin/bash
# username
username_to_backup=<username>
#path to backup storage directory
backup_folder=/home/$username_to_backup/backups
# copy all first-of-the-month files into Archive (COPY!)
# do this first on the basis that this script ran yesterday, and the day before and since at least
# the first of this month, which will eventually be true
cp -p -u $backup_folder/*$(date +"%y%m")01_* $backup_folder/archive/
# do the backups - copy any required/listed files into the backup folders and timestamp them (COPY!)
## bash history
cp /home/$username_to_backup/.bash_history "$backup_folder/bash_history-$(date +"%y%m%d_%H%M%S")"
chmod 644 $backup_folder/bash_history*
## backup scripts
cp $backup_folder/scripts/daily_base_backups.sh "$backup_folder/daily_base_backups-$(date +"%y%m%d_%H%M%S").sh"
# see <hostname> /home/<username>/IDrive_backup_status.sh for comments on the following...
# if latest IDrive backup contained no errors then delete local backups (from /backups but note first-of-the-month files are still in /backups/Archive)
# that are from the month 2 months earlier in the case of incremental MySQL backups (ie on 1st Feb that means anything from December (1st to 31st)), and
# that are from the month 6 months earlier in the case of full MySQL backups, and
# that are from the month 2 months earlier in the case of:
# bash_history
# (as long as they're all still being backed up with the filename structured as at time of writing)
if [[ $(ls -Art /home/$username_to_backup/IDriveForLinux/idriveIt/user_profile/$username_to_backup/idrive@mail-track.co.uk/Backup/DefaultBackupSet/LOGS | tail -n 1 | grep _Success_ | wc -l) -eq 1 ]]
then
#echo Last IDrive backup was a SUCCESS with zero errors
rm -rf $backup_folder/bash_history-$(date --date='-2 month' +"%y%m")*
echo [$(date +"%y%m%d_%H%M%S")] >> $backup_folder/backup_log_CBL_script.txt
echo CBL backup script RAN >> $backup_folder/backup_log_CBL_script.txt
echo IDrive backup SUCCESS >> $backup_folder/backup_log_CBL_script.txt
echo Local files deletion routine RAN. This does not necessarily mean it succeeded. >> $backup_folder/backup_log_CBL_script.txt
echo ie the test for last backup SUCCESS returned TRUE - see commented bash script at >> $backup_folder/backup_log_CBL_script.txt
echo $backup_folder/scripts/daily_base_backups.sh and more detailed at $backup_folder/scripts/IDrive_backup_status.sh >> $backup_folder/backup_log_CBL_script.txt
echo Check latest log at /home/$username_to_backup/IDriveForLinux/idriveIt/user_profile/$username_to_backup/idrive@mail-track.co.uk/Backup/DefaultBackupSet/LOGS/ >> $backup_folder/backup_log_CBL_script.txt
else
#echo Last IDrive backup either failed, was a success with errors or was a MANUAL backup - ie wasn't the scheduled backup we're interested in
echo [$(date +"%y%m%d_%H%M%S")] >> $backup_folder/backup_log_CBL_script.txt
echo CBL backup script RAN >> $backup_folder/backup_log_CBL_script.txt
echo IDrive backup HAD ERRORS>> $backup_folder/backup_log_CBL_script.txt
echo Local files deletion routine DID NOT RUN because IDrive backup had errors >> $backup_folder/backup_log_CBL_script.txt
echo ie the test for last backup success returned FALSE - see commented bash script at >> $backup_folder/backup_log_CBL_script.txt
echo $backup_folder/scripts/daily_backups.sh and more detailed at /home/$username_to_backup/IDrive_backup_status.sh >> $backup_folder/backup_log_CBL_script.txt
echo Check latest log at /home/$username_to_backup/IDriveForLinux/idriveIt/user_profile/$username_to_backup/idrive@mail-track.co.uk/Backup/DefaultBackupSet/LOGS/ >> $backup_folder/backup_log_CBL_script.txt
#do nothing more
fi
Test that the script runs by executing the following and then checking the backup folder for new contents
./backups/scripts/daily_base_backups.sh
That’s the base install I always perform on a new Linux server before installing any specific services or applications. For installation HOW-TOs for others (eg a MariaDB MySQL server, Node-RED, the mosquitto MQTT broker, Unifi wireless controller, BIND9 DNS server, Nagios network monitor, and others) search for “HOW-TO” on this site.
2 Replies to “HOW-TO Install a Reliable Base Server on Raspberry Pi”