Pre-Backup Tasks

  1. Decide what disk/file system areas are needed.

#* }

  1. Decide what information is needed.
  2. Decide what we don't want to backup.
  3. Decide what we can do to make restore easier. Ensure we have that information.
  4. May need to compromise on the restore process.
  5. Decide how often we will backup our system(s).
  6. May need to stop a process or dump a DBMS to text to ensure non-corrupted backups.
  7. May want to create an LVM snapshot to freeze the SOURCE, then use that for backups.

** Empty trash for users, ** Remove any cache/temporary files from areas that will be backed up ** Ensure the target directory exists ** Save crontabs for root and important users ** Save a list of manually installed packages ** Save the current lshw and inxi ** Save the current disk partitions, LVM data, ** Programmers might want to save lists of installed modules for their language

For example, a partial script to put all information to a place that will be backed up.

Code:

     local_backup="/root/backups"
     mkdir $local_backup
     
     echo "INFO: Daily dump of important crontabs to $local_backup/"
     $crontab -l -u root > $local_backup/crontab.root
     if [[ 1 -eq $(/usr/bin/getent passwd jp | wc -l) ]] ; then
        $crontab -l -u jp > $local_backup/crontab.jp
     fi
     if [[ 1 -eq $(/usr/bin/getent passwd www-data | wc -l) ]] ; then
        $crontab -l -u www-data > $local_backup/crontab.www-data
     fi
     if [[ 1 -eq $(/usr/bin/getent passwd typo | wc -l) ]] ; then
        $crontab -l -u typo > $local_backup/crontab.typo
     fi
     if [[ 1 -eq $(/usr/bin/getent passwd munin | wc -l) ]] ; then
        $crontab -l -u munin > $local_backup/crontab.munin
     fi
     if [[ 1 -eq $(/usr/bin/getent passwd ubuntu | wc -l) ]] ; then
        $crontab -l -u ubuntu > $local_backup/crontab.ubuntu
     fi
     if [[ 1 -eq $(/usr/bin/getent passwd zimbra | wc -l) ]] ; then
        $crontab -l -u zimbra > $local_backup/crontab.zimbra
     fi
     $aptmark showmanual > $local_backup/apt-mark.manual
     ######[ to restore pkgs ]#######
     ### sudo apt-mark auto $ ( cat pkgs_auto.lst)
     ### sudo apt-mark manual $ ( cat pkgs_manual.lst)
     ### sudo apt-get -u dselect-upgrade
     # Daily dump of current hardware to /root/backup
     $lshw 2>&1 > $local_backup/lshw.list
     $parted -lm > $local_backup/parted.txt
     $df -Th -x squashfs -x tmpfs -x devtmpfs > $local_backup/df.txt
     $pvs 2>&1 > $local_backup/pvs.txt
     $vgs 2>&1 > $local_backup/vgs.txt
     $lvs 2>&1 > $local_backup/lvs.txt
     $blkid > $local_backup/blkid.txt
     $lsblk -e 7 -o name,size,type,fstype,mountpoint > $local_backup/lsblk.txt
     $inxi -Fxx > $local_backup/inxi.txt
     if [[ -f $gem ]] ; then
        $gem list --local > $local_backup/gem.list
     fi
     # Get list of installed perl modules, if any
     if [[ -f $cpan ]] ; then 
        if [[ -d /usr/local/lib/site_perl || \
              -d /usr/share/perl/*/App ]] ; then
           $cpan -l > $local_backup/cpan.list
        fi
     fi

2023-Backup-How-To

Last Update: 2023-02-09