I am just a ict fanatic with years of reading knowledge. I do not administer outside my own home.
A True backup consist of several data copies and can differ from size.
Approach one :
Create a full system backup once ( this optionally includes nextcloud installation and optionally the user data ) this may take some time and is best done with minimal services running.
once this backup is complete, you create a copy of that backup, which you will store in a secure fire retardant box atleast 5km from the other backup which should also be placed in a fire retardant box.
then run a backup every X ( day / week / month depending on your activity ) that only copies / delete files that have been changed / added or removed and again repeat this process for the 2nd backup disk ( back in the days we used tape streamers ).
this backup type is called incremental and is in my opinion the best method.
besides these backups I would still recommend to make a SQL DATABASE backup aside ( all databases not only nextcloud ) .
ps. Very few backups follow these rules but it’s the only way
Backup by cloning :
This backup type is widely used by desktop suppliers where you buy a Desktop with windows pre installed.
Offices-es use them to setup workstations.
They setup a workstation once. Then multiply the disk by cloning and put a copy in each workstation where the employees login all have the same software pre-installed.
This can ofcourse also be applied to pre-installed servers.
Where as you now see Docker which is basicly a clone of the software running in a vm. ( roughly seen through my eyes ) .
This is by far the easiest method and has been my favorite in the beginning of my ict learning so 30 years ago using the software Ghost by symantec before I knew dd the easy way to do it
VM Export :
Personaly I only have experience with virtualbox. Where you assume correct a VM can be exported to anything large enough to keep your data. and when imported on a different machine it should still work. Besides the networking you have set on any HOST machine. ex. if you set iptables to forward a port to a vm you will have to redo that when using a different HOST.
this is all what I can say and is all minimalistic information of what there is of information.
for all backup types it is required/preferred to umount your disk so that there is no activity current.
my advice as I read your post is :
get DSL ( Damn small linux ) or tinyCore or any other
create a VM
install above linux
Personalize or mark the system
export VM
backup exported VM
delete VM ( not the backup ofcourse )
restore VM ( from the backup )
see do and learn
here are some quick links about incremental backups using rsync read them then search for some more information.
https://linuxconfig.org/how-to-create-incremental-backups-using-rsync-on-linux
https://www.perfacilis.com/blog/systeembeheer/linux/incremental-back-up-script-using-rsync.html
finally to close it off this is what I use to backup nextcloud installation and nextcloud database.
I store my NC user data outside the installation folder so to run this back-up takes about 2 min although it depends on how many apps are installed and files are stored.
If you like to use this work in progress notice it’s made for ME so adjust to your needs.
you need to create a file db_auth.cfg that will store your db password for your root user ( I should fix this insecurity )
echo SQL-root-password | base64 > db_auth.cfg && sed -i '1s/^/DB_NC=/' db_auth.cfg; sleep 2 && chmod 400
#!/bin/bash
#
# Nextcloud Settings Script
# for backingup Nextcloud
#
source db_auth.cfg
ncpath='/var/www/nextcloud' # ADJUST NC Installation location
bckuppath='/home/USERNAME/nextcloud-backup/' # ADJUST Where to store the backup ( trailing slash / )
htuser='www-data'
htgroup='www-data'
rootuser='root' # User to connect to the mysql database
database='nextcloud' # ADJUST Database name
version=$(cat $ncpath/version.php | head -n 2 | tail -n1 | awk '{ print $3 }' | cut -c 7-14 | sed 's/,/./g')
sbt=$(date +"%x-%H:%M")
dbp=$(eval echo ${DB_NC} | base64 --decode)
function version {
printf "What version Nextcloud are you running\n"
read -p "Version: " version
if [[ $version == "" ]]; then
version
else
startup
fi
}
function startup {
echo
echo "Nextcloud Version: ${version}"
echo
echo "Set Maintenance to BACKUP or for PRODUCTION"
echo "1: PRODUCTION"
echo "2: BACKUP"
echo "3: RESTORE"
echo "0: EXIT"
read -p "Choose 1,2 or 3: " ans
if [[ $ans == "1" ]]
then
production
startup
elif [[ $ans == "2" ]]
then
full
startup
elif [[ $ans == "3" ]]
then
restore
else
quit
fi
}
function production {
printf "Setting Maintenance mode off\n"
echo " Choose y/n "
read -p " Setting Maintenance mode off: [y/n] " prod
if [[ $prod == "y" ]]; then
sudo -u ${htuser} php ${ncpath}/occ maintenance:mode --off
else
echo " Maintenance Mode still ON "
fi
echo " Finished "
}
function full {
read -p " Answer all Yes: [y/n] " fbckup
if [[ $fbckup == "n" ]]; then
backup
else
echo " Turning on maintenance:mode "
sudo -u ${htuser} php ${ncpath}/occ maintenance:mode --on
echo " Back-up ${ncpath} "
# Remove --exclude 'data' in the next line to include the data directory to your backup
sudo rsync -Aavx --exclude 'data' ${ncpath}/ ${bckuppath}nextcloud-${version}-`date +"%x-%H:%M"`/
echo " Back-up SQL Database to nextcloud-${version}-${sbt}.sql "
mysqldump --single-transaction --default-character-set=utf8mb4 -u ${rootuser} -p${dbp} ${nextcloud} > ${bckuppath}nextcloud-${version}-`date +"%x-%H:%M"`.sql
echo " Turning off maintenance:mode "
sudo -u ${htuser} php ${ncpath}/occ maintenance:mode --off
fi
echo " Back-up Complete "
quit
}
function backup {
# Sets permissions of the Nextcloud instance for backing up
echo " Choose y/n "
read -p " Setting Maintenance mode on: " yn
if [[ $yn == "y" ]]; then
sudo -u ${htuser} php ${ncpath}/occ maintenance:mode --on
else
echo " Maintenance mode still OFF "
fi
echo " Choose y/n "
read -p " Create backup of '${ncpath}' : " yn1
echo
if [[ $yn1 == "y" ]]
then
# Remove --exclude 'data' in the next line to include the data directory to your backup
sudo rsync -Aavx --exclude 'data' ${ncpath}/ ${bckuppath}nextcloud-${version}-`date +"%x-%H:%M"`/
else
echo " Not Backing up '${ncpath}' "
fi
echo " Choose y/n "
read -p " Create backup of MYSQL database 'nextcloud' : " yn2
echo
if [[ $yn2 == "y" ]]
then
mysqldump --single-transaction --default-character-set=utf8mb4 -u ${rootuser} -p${dbp} ${nextcloud} > ${bckuppath}nextcloud-${version}-`date +"%x-%X"`.sql
else
echo " Not backing up 'nextcloud' database "
fi
echo
echo " Finished "
echo " Turning off maintenance:mode "
sudo -u ${htuser} php ${ncpath}/occ maintenance:mode --off
}
function restore {
dirs=($bckuppath*/)
read -p "$(
f=0
for dirname in "${dirs[@]}" ; do
echo "$((++f)): $dirname"
done
echo -ne 'Please select a directory > '
)" selection
selected_dir="${dirs[$((selection-1))]}"
echo "You selected '$selected_dir'"
}
function quit {
echo
echo "Peace out."
exit
}
startup
echo " foo "
this will create a backup of your installation like so
510M nextcloud-backup/nextcloud-20.0.7.1-22-04-21-13:17
533M nextcloud-backup/nextcloud-20.0.9.1-28-04-21-01:53
580M nextcloud-backup/nextcloud-21.0.2.1-23-05-21-20:32
580M nextcloud-backup/nextcloud-21.0.2.1-23-05-21-21:39
580M nextcloud-backup/nextcloud-21.0.2.1-23-05-21-21:51
580M nextcloud-backup/nextcloud-21.0.2.1-23-05-21-21:54
580M nextcloud-backup/nextcloud-21.0.2.1-23-05-21-22:00
580M nextcloud-backup/nextcloud-21.0.2.1-25-09-21-03:13
595M nextcloud-backup/nextcloud-21.0.5.1-18-11-21-00:09
608M nextcloud-backup/nextcloud-22.2.3.0-18-11-21-00:31
640M nextcloud-backup/nextcloud-22.2.5.1-07-03-22-14:23
711M nextcloud-backup/nextcloud-23.0.3.2-22-04-22-20:04
714M nextcloud-backup/nextcloud-23.0.4.1-02-05-22-14:30
698M nextcloud-backup/nextcloud-23.0.4.1-06-05-22-22:05
and for the database
-rw-rw-r-- 1 vincent vincent 200M apr 22 2021 nextcloud-backup/nextcloud-20.0.7.1-22-04-21-13:18.sql
-rw-rw-r-- 1 vincent vincent 194M apr 28 2021 nextcloud-backup/nextcloud-20.0.9.1-28-04-21-01:55:14.sql
-rw-rw-r-- 1 vincent vincent 183M mei 23 2021 nextcloud-backup/nextcloud-21.0.2.1-23-05-21-20:34:45.sql
-rw-rw-r-- 1 vincent vincent 183M mei 23 2021 nextcloud-backup/nextcloud-21.0.2.1-23-05-21-21:57:18.sql
-rw-rw-r-- 1 vincent vincent 183M mei 23 2021 nextcloud-backup/nextcloud-21.0.2.1-23-05-21-22:01.sql
-rw-rw-r-- 1 vincent vincent 249M sep 25 2021 nextcloud-backup/nextcloud-21.0.2.1-25-09-21-03:14.sql
-rw-rw-r-- 1 vincent vincent 308M nov 18 00:10 nextcloud-backup/nextcloud-21.0.5.1-18-11-21-00:10.sql
-rw-rw-r-- 1 vincent vincent 308M nov 18 00:31 nextcloud-backup/nextcloud-22.2.3.0-18-11-21-00:31.sql
-rw-rw-r-- 1 vincent vincent 288M mrt 7 14:23 nextcloud-backup/nextcloud-22.2.5.1-07-03-22-14:23.sql
-rw-rw-r-- 1 vincent vincent 264M apr 22 20:04 nextcloud-backup/nextcloud-23.0.3.2-22-04-22-20:04.sql
-rw-rw-r-- 1 vincent vincent 265M mei 2 14:30 nextcloud-backup/nextcloud-23.0.4.1-02-05-22-14:30.sql
-rw-rw-r-- 1 vincent vincent 265M mei 6 22:07 nextcloud-backup/nextcloud-23.0.4.1-06-05-22-22:07.sql
This is in no way associated with NC there is no support available what so ever. If admins find this not fit for learning feel free to remove it.