16 tguess Freeing harddisk space: select, backup, delete

Contents of this section

If you don't have enough room on your harddisk for new things, you often want to backup some old stuff (e.g. a program source tree) and delete it to get more free space. Tbackup supports this with the tdir command and the setrm method.

You can use the tdir command to interactively make a temporary directory set called tdir, containing the things you want to back up and delete.

You can then back up the tdir set with the setrm choose method, that will delete the directories in the set once the backup is finished.

If you need some of the old stuff again, you can easily grep the backup index files for it and do a partial restore.

16.1 Running tdir

tdir is a command line tool for making directory sets. You can use it in the following ways:

tdir

Without any options tdir will list the contents of the tdir directory set.

tdir [-s setname] -c|-create description

With the -c or -create option you can create a new directory set. If you don't specify a set name with the -s option, tdir will work on the tdir directory set.

tdir [-s setname] dirname/filename [...]

If you give file or directory names to tdir they are added to the directory set.

tdir [-s setname] not name|ext|dir|fullname string/"pattern" [...]

not instructions can be added in the same way. Patterns must be quoted to prevent expansion by the shell.

tdir [-s setname] -d|-delete|-e|-edit|-l|-list|-u|-undoadd

The other directory set operations are:

-d or -delete

deletes tdir.set (or setname.set).

-e or -edit

runs the editor vi on the directory set. If you don't like vi you can configure another editor in the file /etc/tbackup/Config.

-l or -list

lists the contents of the directory set.

-u or -undoadd

removes the last line from the directory set, thus undoing a previous tdir command.

Here is a sample transcript:

First we look at the tdir help information:

~# tdir -h
   ^^^^^^^
tdir usage:
  tdir [-s setname] -c|-create <description>
  tdir [-s setname] <dirname/filename> [...]
  tdir [-s setname] not name|ext|dir|fullname <string/"pattern"> [...]
  tdir [-s setname] -d|-delete|-e|-edit|-l|-list|-u|-undoadd
man tdir gives more help.
We want to select some old stuff from /usr/src:
~# cd /usr/src
   ^^^^^^^^^^^
We create the directory set tdir, titled some source files:
/usr/src# tdir -c some source files
          ^^^^^^^^^^^^^^^^^^^^^^^^^
Created directory set /etc/tbackup/tdir.set.
Current contents of /etc/tbackup/tdir.set:
     1  # some source files
Then we use ls so see what old stuff we can throw away:
/usr/src# ls
          ^^
cpio-2.3           defrag             perl-4.036         util-linux-1.5
gzip-0.7           mtools             traceroute         xview
gzip-1.2.3         ncurses-1.8.1      utree
We don't need the defrag source tree anytime soon, so we put it in tdir.set:
/usr/src# tdir defrag
          ^^^^^^^^^^^
Added directory "/usr/src/defrag" to tdir.set.
Just typing tdir lists the current contents of the directory set:
/usr/src# tdir
          ^^^^
Current contents of /etc/tbackup/tdir.set:
     1  # some source files
     2  /usr/src/defrag
Now we add some more stuff. Note that you can use wildcards:
/usr/src# tdir gzip* utree
          ^^^^^^^^^^^^^^^^
Added directory "/usr/src/gzip-0.7" to tdir.set.
Added directory "/usr/src/gzip-1.2.3" to tdir.set.
Added directory "/usr/src/utree" to tdir.set.
You can also use full path names:
/usr/src# tdir /usr/lib/*hash
          ^^^^^^^^^^^^^^^^^^^
Added file "/usr/lib/dutch.hash" to tdir.set.
Added file "/usr/lib/english.hash" to tdir.set.
We exclude object files from the backup:
/usr/src# tdir not ext .o
          ^^^^^^^^^^^^^^^
Added predicate "not ext .o" to tdir.set.
Before running tbackup we list the directory set again:
/usr/src# tdir
          ^^^^
Current contents of /etc/tbackup/tdir.set:
     1  # some source files
     2  /usr/src/defrag
     3  /usr/src/gzip-0.7
     4  /usr/src/gzip-1.2.3
     5  /usr/src/utree
     7  /usr/lib/dutch.hash
     8  /usr/lib/english.hash
     9  not ext .o
tdir -h gives help

16.2 The setrm method

With the setrm method we can now back up and remove the contents of the tdir directory set. Here is a transcript:

/usr/src# tbackup
          ^^^^^^^      
Available choose methods:
  1 set   -- back up a directory set
  2 setrm -- back up a directory set, then remove its contents
  3 one   -- one user specified file or directory and below
Enter method name or number ---> [set] setrm
                                       ^^^^^
Available directory sets:
1    mystuff    # my stuff in the /root directory.
2    system     # system files
3    tdir       # some source files
4    test       # test set 
Enter set name or number ---> [tdir] 
                                     ^(pressed enter)
WARNING: The `not' instructions in this directory set, i.e.
     1  not ext .o
exclude files and/or directories from the archive, but they do not
exclude them from deletion.
The deletion phase of setrm removes ALL files and directories in the
set, i.e.
        /usr/lib/dutch.hash    /usr/lib/english.hash  /usr/src/defrag
        /usr/src/gzip-0.7      /usr/src/gzip-1.2.3    /usr/src/utree
and everything below, regardless of `not' instructions.
 
Press ^C to abort, enter to continue.
                                     ^(pressed enter)
Available pack methods:

[...]

Make a backup index file ---> (y/n) [y] y
                                        ^
[...]

Backup in progress...

[...]

Please confirm that this backup was successful.
 
Ready to remove all files and directories in tdir, i.e.
        /usr/lib/dutch.hash    /usr/lib/english.hash  /usr/src/defrag
        /usr/src/gzip-0.7      /usr/src/gzip-1.2.3    /usr/src/utree
and everything below.
 
Remove all these files and directories?---> (y/n) [y] y
                                                      ^
Removing.....
 
Cleaning up...
 
Backup completed.
#
We no longer need tdir.set:
/usr/src# tdir -d
          ^^^^^^^
Set /etc/tbackup/tdir.set deleted.
/usr/src# 

Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter