Xml file for the kvm stored?


frodr

Recommended Posts

@frodr I use the following user script running once a day someone posted here on the forum. Can't find the source right now. It saves the xml and the NVRAM files in a zip file in the path you have to set at the top. Backups older than 30 days gets cleaned out with every run.

 

#!/bin/bash
#backs up
#change the location below to your backup location 
backuplocation="/mnt/user/Backup/vm_settings/"

# do not alter below this line
timestamp=`date '+%Y-%m-%d__%H-%M-%S'`
dir="$backuplocation"vm_settings/"$timestamp"
# dont change anything below here
if [ ! -d $dir ] ; then
 
			echo "making folder for todays date $timestamp"

			# make the directory as it doesnt exist
			mkdir -vp $dir
		else
			echo "As $dir exists continuing."
			fi

echo "Saving vm xml files"
rsync -a --no-o /etc/libvirt/qemu/*xml $dir/xml/
echo "Saving ovmf nvram"
rsync -a --no-o /etc/libvirt/qemu/nvram/* $dir/nvram/
chmod -R 777 $dir

		echo "information: creating ZIP-archive and cleaning up old data"
    zip -r -9 "$backuplocation"vm_settings/"$timestamp".zip "$backuplocation"vm_settings/"$timestamp" && rm -r "$backuplocation"vm_settings/"$timestamp" 

		# Amendmend to the original script of danioj by Deeks 2017
		# Delete all backups older than 2 days ONLY if newer files exist
		# Two remarks for quick and easy testing 
		# 1. Line 148 : Set parameter --> actually_copy_files="0"
		# 2. Lines 1068 & line 1070 : Use parameter -mmin in stead of -mtime to test with minutes rather than days
		
		# Credits for this code to JBRELAND on https://tinyurl.com/ycrrbobv

		echo "information: cleaning out backups older than 30 days in location ONLY if newer files exist" $backuplocation/
		for j in $backuplocation/
		do
		  if [[ -n $(find "$j" -type f -mtime -29) ]]; then
		    #echo "debug: valid criteria to enter loop"
		    find "$j" -type f -mtime +30 -exec rm -f {} \;
		  fi 
		  #echo "debug: ended if sequence after loop"
		done

sleep 5
exit

 

Link to comment
2 hours ago, bastl said:

@frodr I use the following user script running once a day someone posted here on the forum. Can't find the source right now. It saves the xml and the NVRAM files in a zip file in the path you have to set at the top. Backups older than 30 days gets cleaned out with every run.

 


#!/bin/bash
#backs up
#change the location below to your backup location 
backuplocation="/mnt/user/Backup/vm_settings/"

# do not alter below this line
timestamp=`date '+%Y-%m-%d__%H-%M-%S'`
dir="$backuplocation"vm_settings/"$timestamp"
# dont change anything below here
if [ ! -d $dir ] ; then
 
			echo "making folder for todays date $timestamp"

			# make the directory as it doesnt exist
			mkdir -vp $dir
		else
			echo "As $dir exists continuing."
			fi

echo "Saving vm xml files"
rsync -a --no-o /etc/libvirt/qemu/*xml $dir/xml/
echo "Saving ovmf nvram"
rsync -a --no-o /etc/libvirt/qemu/nvram/* $dir/nvram/
chmod -R 777 $dir

		echo "information: creating ZIP-archive and cleaning up old data"
    zip -r -9 "$backuplocation"vm_settings/"$timestamp".zip "$backuplocation"vm_settings/"$timestamp" && rm -r "$backuplocation"vm_settings/"$timestamp" 

		# Amendmend to the original script of danioj by Deeks 2017
		# Delete all backups older than 2 days ONLY if newer files exist
		# Two remarks for quick and easy testing 
		# 1. Line 148 : Set parameter --> actually_copy_files="0"
		# 2. Lines 1068 & line 1070 : Use parameter -mmin in stead of -mtime to test with minutes rather than days
		
		# Credits for this code to JBRELAND on https://tinyurl.com/ycrrbobv

		echo "information: cleaning out backups older than 30 days in location ONLY if newer files exist" $backuplocation/
		for j in $backuplocation/
		do
		  if [[ -n $(find "$j" -type f -mtime -29) ]]; then
		    #echo "debug: valid criteria to enter loop"
		    find "$j" -type f -mtime +30 -exec rm -f {} \;
		  fi 
		  #echo "debug: ended if sequence after loop"
		done

sleep 5
exit

 

Thanks.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.