Posted By

garretjames on 01/15/15


Bash backup linux backintime

Versions (?)

Callback Script for Back In Time

 / Published in: Bash


There is a user-callback example in which will backup all package selections, sources and repository keys which are necessary to reinstall exactly the same packages again. It will even backup whether a package was installed manually or automatically because of dependencies.

Download the script, copy it to '~/.config/backintime/user-callback' and make it executable with 'chmod 755 ~/.config/backintime/user-callback'

It will run every time a new snapshot is taken. Make sure to include '~/.apt-backup'

  1. #!/bin/sh
  2. # Copyright (c) 2012-2014 Germar Reitze
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along
  15. # with this program; if not, write to the Free Software Foundation, Inc.,
  16. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. # backup selection of apt-get
  19. # Take a look at
  20. #
  21. #
  23. profile_id="$1"
  24. profile_name="$2"
  25. reason="$3"
  26. errorcode="$4"
  27. DST="$HOME/.apt-backup"
  29. case $reason in
  30. 1) #on process begin
  31. mkdir -p $DST
  32. dpkg --get-selections > $DST/package.list
  33. apt-mark showauto > $DST/pgk_auto.list
  34. apt-mark showmanual > $DST/pgk_manual.list
  35. rm -f $DST/sources.list.d/*
  36. cp -aR /etc/apt/sources.list* $DST/
  37. apt-key exportall > $DST/repo.keys
  38. ;;
  39. esac

Report this snippet  


RSS Icon Subscribe to comments
Posted By: garretjames on January 15, 2015

If you made snapshots including apt-get package selection as described in you can easily restore your system after a disaster/on a new machine.

1) install Debian/Ubuntu on your new hard drive as usual 2) install backintime-gnome (or backintime-kde) from Software Centre 3) run 'mkdir -p ~/.config/backintime' (or if you run BackInTime as root before 'sudo mkdir -p /root/.config/backintime') 4) find 'config' file in the last snapshots root folder (e.g. '/media/USER/drive/backintime/HOST/USER/1/20131121-221500-123/config') and copy this into the folder which you created in 3) 5) start BackInTime. If it doesn't find you snapshots directly, open 'Settings', disable 'Auto Host / User / Profile Id' and change 'Host' and 'User' entry so they match your old machine 6) restore your home 7) recreate your '/etc/apt/sources.list' if you had something special in there. If your Debian/Ubuntu version changed don't just copy them from '~/.apt-backup/sources.list' 8) copy your repositories with 'sudo cp ~/.apt-backup/sources.list.d/* /etc/apt/sources.list.d/' 9) restore apt-keys for your PPA's with 'sudo apt-key add ~/.apt-backup/repo.keys' 10) install and update dselect with 'sudo apt-get install dselect && sudo dselect update install' 11) make some "housecleaning" in '~/.apt-backup/package.list'. For example you don't want to install the old kernel again. So run 'sed -e "/^linux-(image\|headers)/d" -i ~/.apt-backup/package.list' 12) install your old packages again with 'sudo apt-get update && sudo dpkg --set-selections < ~/.apt-backup/package.list && sudo apt-get dselect-upgrade'

If you used the new script which uses apt-mark to backup package selection proceed with 13) (there should be files '~/.apt-backup/pkgauto.list' and '~/.apt-backup/pkgmanual.list'). Otherwise you can stop here.

13) restore package selection with 'sudo apt-mark auto $(cat ~/.apt-backup/pkgauto.list) && sudo apt-mark manual $(cat ~/.apt-backup/pkgmanual.list)

Posted By: garretjames on January 15, 2015

You need to login to post a comment.