dergachev/vagrant-vbox-snapshot

Ability to specify a directory of snapshots

Closed this issue · 3 comments

Is there a way to do the subject?

Not sure what you mean, please clarify.

Sorry, i've achieved the goal, but forgot to close this issue. If somebody interesting, in Vagrantfile:

def going_up?
  ARGV[0] == "up"
end

def setup_snapshots_dir(v, name)
  dir_path = Pathname.new("#{__dir__}/../tmp/snapshots/#{name}").cleanpath
  if going_up?
    if ! Dir.exists?(dir_path)
      FileUtils.mkpath(dir_path)

      # It should be one time. So, if the directory exists, but there is no VM, you should delete it in advance.
      v.customize ["modifyvm", :id, "--snapshotfolder", dir_path]
    end
  end
end

# Somewhere below
node.vm.provider "virtualbox" do |v|
  setup_snapshots_dir(v, node.vm.hostname)
end

Great, and thank you for sharing your solution!