How to make auto snapshot on Linux?

 how to set bash with time in Linux



How to take snapshots in VirtualBox using sh file
How to take snap


how to set bash with time in Linux


now set take snapshot and delete snapshot automatically 
we can set time frame or schedule for that


01 type cd  /usr/bin
then showing like this 
CD  /usr/bin



02 type sudo nano add1.sh
 
sudo nano add1.sh


#!/bin/bash 
sleep   `echo $(VBoxManage snapshot "lubuntu64 bits" take "now")` # Place your code>

VBoxManage snapshot

sudo chmod +x add1.sh

sudo chmod +x add1.sh

./add1.sh

./add1.sh



that way make take snapshot using sh on linux 

now we try make delete snapshot using sh 

sudo nano delete1.sh


 sleep `echo $(VBoxManage snapshot "lubuntu64 bits" delete "now")` # Place >

after run

sudo chmod +x delete1.sh

./delete1.sh



now we made a schedule using these two sh 
make new sh call summary.sh

sudo nano summary.sh
after 

sudo echo "/usr/bin/add1.sh" | at 1:00Am
sudo echo "/usr/bin/add1.sh" | at 2:00Am
sudo echo "/usr/bin/add1.sh" | at 3:00Am
sudo echo "/usr/bin/add1.sh" | at 4:00Am
sudo echo "/usr/bin/add1.sh" | at 5:00Am
sudo echo "/usr/bin/add1.sh" | at 6:00Am
sudo echo "/usr/bin/add1.sh" | at 9:00Am
sudo echo "/usr/bin/add1.sh" | at 12:00pm
sudo echo "/usr/bin/add1.sh" | at 3:00pm
sudo echo "/usr/bin/add1.sh" | at 6:00pm
sudo echo "/usr/bin/add1.sh" | at 9:00pm
sudo echo "/usr/bin/delete1.sh" | at 1:05Am
sudo echo "/usr/bin/delete1.sh" | at 2:05Am
sudo echo "/usr/bin/delete1.sh" | at 3:05Am
sudo echo "/usr/bin/delete1.sh" | at 4:05Am
sudo echo "/usr/bin/delete1.sh" | at 5:05Am
sudo echo "/usr/bin/delete1.sh" | at 6:05Am
sudo echo "/usr/bin/delete1.sh" | at 9:05Am
sudo echo "/usr/bin/delete1.sh" | at 12:05pm
sudo echo "/usr/bin/delete1.sh" | at 3:05pm
sudo echo "/usr/bin/delete1.sh" | at 6:05pm
sudo echo "/usr/bin/delete1.sh" | at 9:05pm


copy the above time schedule you can change it as you want 




sudo chmod +x summary.sh



if you show an error then you should install at as bellow 

sudo apt install at


now work our at command


./summary.sh

Now how to set this work as a loop on everyday 
try this way 
sudo nano everyday.sh


#!/bin/bash
while ( true ); do
  before=`date +%s`
  sleep `echo "/usr/bin/summary.sh" | at 11:16pm` # Place your command here
  after=`date +%s`
  DELAY=`echo "86400-($after-$before)" | bc`
  sleep $DELAY
done

after 
sudo chmod +x everyday.sh

after 
./everyday.sh



As you can see it will take autos a nap and it will delete old snap auto using our bash 




when deleting a snap it always delete 1st snap it means old snap, not any way delete the latest snap, that will match your aim
 
if you have any issues message us we will help you

thank you 

Post a Comment

1 Comments