You are not logged in.

#1 2013-08-10 19:24:16

manuelschneid3r
Member
From: Germany
Registered: 2013-04-14
Posts: 152

System backup via tar. Which files to exclude?

Hi

I found in an ubuntu article this command:

tar cvpzf backup.tgz --exclude=/proc --exclude=/lost+found --exclude=/backup.tgz --exclude=/mnt --exclude=/sys /

to backup the whole system. But, shouldn't I exclude /dev, as the entries are dynamically generated by udev, an /tmp, because this files are just temporary and not relevant for the backup?

Further, are there any other files I can exclude too?

Last edited by manuelschneid3r (2013-08-10 19:24:39)


Please feel free to correct my english.

Offline

#2 2013-08-10 20:10:19

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: System backup via tar. Which files to exclude?

https://wiki.archlinux.org/index.php/Fu … p_with_tar
I guess /run and /sys don't need to be backed up either.

Exclude stuff you don't care about. If you downloaded tens of GB of media that you're going to watch and remove, you don't have to back them up, as long as redownloading in case of e.g. hardware failure is not a problem and you still have the urls from where to download them backed up.

Offline

#3 2013-08-10 20:21:13

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: System backup via tar. Which files to exclude?

Also, /tmp and /media (if it exists) are other common excludes.

Basically, you can look through the output of 'mount' to get a good idea of what things you don't need.

Offline

#4 2013-08-10 20:45:03

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: System backup via tar. Which files to exclude?

WonderWoofy wrote:

Also, /tmp and /media (if it exists) are other common excludes.

OP already mentioned /tmp and isn't /media empty by default? There's no harm in backing up a bunch of directories, unless you have some stuff mounted there.

WonderWoofy wrote:

Basically, you can look through the output of 'mount' to get a good idea of what things you don't need.

Ummm

$ mount
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=508148k,nr_inodes=127037,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
/dev/sda3 on / type ext3 (rw,relatime,data=ordered)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=24,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,relatime)
/dev/sda4 on /home type ext3 (rw,relatime,data=ordered)

;P

Offline

#5 2013-08-10 21:21:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: System backup via tar. Which files to exclude?

Yeah, so I guess I look through that and I can see that the user/admin has specified mounts on / and /home.  So the other things must all be API filesystems that are automagically mounted by systemd.  Of course, if you specify /sys then you can omit all the cgroup stuff that resides below that, and devtps for example is already taken care of by the mount of devtmpfs. 

Maybe I'm assuming too much?

Offline

#6 2013-08-11 00:08:23

stryder
Member
Registered: 2009-02-28
Posts: 500

Re: System backup via tar. Which files to exclude?

Use this, https://bbs.archlinux.org/viewtopic.php?id=156522,  or read through the bash script?

Offline

#7 2013-08-11 19:39:54

jamesbond007
Member
From: Germany
Registered: 2009-06-14
Posts: 150

Re: System backup via tar. Which files to exclude?

Hi manuelschneid3r,

here are some additional directories I would exclude from backup:

- /home/<user>/.mozilla/firefox/*/Cache/
- /home/<user>/.local/share/Trash/
- /home/<user>/.cache/
- /home/<user>/tmp/

Kind regards,
jamesbond007.

Offline

#8 2013-08-11 19:44:50

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: System backup via tar. Which files to exclude?

From my /home/<user> directory I back up only some dotfiles and a couple user-created directories with pictures, docs etc.
Even ~/.config can have a lot of stuff that's of not much use.

I our recommendations we're drifting away from a full system backup to a more personalized and focused one.

Last edited by karol (2013-08-11 19:46:07)

Offline

#9 2013-08-12 07:58:58

Regalis
Member
From: Poland::Cracow
Registered: 2012-02-08
Posts: 4
Website

Re: System backup via tar. Which files to exclude?

Hi,

@manuelschneid3r: I see you exclude mostly standard mountpoints like /proc and /sys, to avoid this, you can do something like this:

# mkdir /mnt/root
# mount --bind / /mnt/root -o ro
# tar -C /mnt/root -c . (...)

This will provide you clean root partition (without any mount points inside) in /mnt/root.


Best regards,
Regalis

Offline

#10 2013-08-12 14:08:46

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: System backup via tar. Which files to exclude?

@Regalis, You don't even need to bind mount.  You can actually just mount your filesystem at multiple places, so this would work without the "--bind" as well.  But as long as you don't use "--rbind" you should be okay.

Offline

#11 2016-08-13 13:11:00

rafnov
Member
Registered: 2014-11-12
Posts: 5

Re: System backup via tar. Which files to exclude?

Do you by any chance know why --exclude=/sys/* does not exclude /sys nowadays?
One source I've found on web (http://www.aboutdebian.com/tar-backup.htm) tells to omit / sign when excluding dirs, but it was working just some months ago with /.

I have my old backup script which I was using couple of years but it stopped working lately:

#!/bin/bash

taropcje="--create --preserve-permissions --totals --gzip --ignore-failed-read --file"
data=`date +%Y.%m.%d`
kat=/home/kopia
katkopia=$kat/$(uname -n)/$data
rm -rf /home/kopia/*
mkdir -p $katkopia

wylacz="
--exclude=$katkopia/*
--exclude=/dev/*
--exclude=/dane/*
--exclude=/home/*
--exclude=/proc/*
--exclude=/mnt/*
--exclude=/sys/*
--exclude=/tmp/*
--exclude=/run/media/*"

wylacz_home="
--exclude=/home/pobrane/*
--exclude=/home/kopia/*"

umount /mnt/*

cd /
nice -n 19 tar $taropcje $katkopia/root-$data.tar.gz / $wylacz

cd /home
nice -n 19 tar $taropcje $katkopia/home-$data.tar.gz /home/rav $wylacz_home

There are my-language variable names there but syntax should explain itself.

/sys/* isn't omitted and script spitss out tons of errors.
Any tip how to fix it / improve my script?

Offline

Board footer

Powered by FluxBB