[GRASSLIST:1919] Export Raster

Hi all,

I need to remove some grass rasters from my HD since
it's almost filled up, but I don't want to loose the
files. What would be the best way to do this? Is there
such a command like export, so I can do a safe backup
of the files? Should I use r.out.ascii, r.out.bin? Or
just copy the entire directory?

Thanks

Daniel

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

Daniel Victoria wrote:

I need to remove some grass rasters from my HD since
it's almost filled up, but I don't want to loose the
files. What would be the best way to do this? Is there
such a command like export, so I can do a safe backup
of the files? Should I use r.out.ascii, r.out.bin? Or
just copy the entire directory?

Backing-up an entire mapset is simple enough; just use tar/zip/etc on
the mapset directory. Similarly for entire locations.

Backing-up individual maps is a bit more involved; however, all files
pertaining to a given map have the same name as the map, except for
those in the cell_misc directory, which reside in a subdirectory with
the same name as the map. In both cases, the file/directory in
question will exist in a subdirectory of the mapset directory. So you
could use e.g.:

  cd <database>/<location>/<mapset>
  tar cf <mapname>.tar */<mapname>

Using r.out.* will discard the category labels, colour table, history
etc, so it isn't a particularly good mechanism for creating backups.

--
Glynn Clements <glynn.clements@virgin.net>

Hi all,

Thanks Glynn for the help.

But imagine this, you have 300 rasters and want to
erase half, but keep a backup. Wouldn't it be
easier/better to have a way to backup just those
rasters and not the entire dataset? Then, if later on,
I want to restore just 10 of those 150 backup rasters,
It would be very easy o do. Maybe some sort of export
program designed to export from Grass to a interchange
file and back to Grass, like the export program in
ARC...

Of course, since it's just a matter of getting all the
files and directories with the same name as the
raster, a simple shell script will do the trick...
I'll try to work on that and if successful, post it to
the list, but keep in mind that I'm a newbie at
programing... If anyone beats me to the task, feel
free to contribute :slight_smile:

Daniel

--- Glynn Clements <glynn.clements@virgin.net> wrote:

Daniel Victoria wrote:

> I need to remove some grass rasters from my HD
since
> it's almost filled up, but I don't want to loose
the
> files. What would be the best way to do this? Is
there
> such a command like export, so I can do a safe
backup
> of the files? Should I use r.out.ascii, r.out.bin?
Or
> just copy the entire directory?

Backing-up an entire mapset is simple enough; just
use tar/zip/etc on
the mapset directory. Similarly for entire
locations.

Backing-up individual maps is a bit more involved;
however, all files
pertaining to a given map have the same name as the
map, except for
those in the cell_misc directory, which reside in a
subdirectory with
the same name as the map. In both cases, the
file/directory in
question will exist in a subdirectory of the mapset
directory. So you
could use e.g.:

  cd <database>/<location>/<mapset>
  tar cf <mapname>.tar */<mapname>

Using r.out.* will discard the category labels,
colour table, history
etc, so it isn't a particularly good mechanism for
creating backups.

--
Glynn Clements <glynn.clements@virgin.net>

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

Hi all,

Just to finish the topic.

I made 2 shell scripts, one that will tar/bzip2 all
maps with a specific name to a tar.bz2 file and the
other that will unpack it. The unpacking is not
necessary since it can be done by simply using the
command
tar -jxPvf file_name
the P is to keep the original file path

Hope it can be usefull to anyone. Feel free to change
it as you see fit

Cheers
Daniel

------export script------
#/bin/sh
#Export script for grass...
#gets all files and dirs that matches the pattern
entered by the user
#tars and bzip2 all files
#created by Daniel de Castro Victoria on 12/02/2003
#daniel_victoria@yahoo.com

echo Enter export file name:
read outfile
echo Enter name pattern:
read pattern

tar -jcPvf $outfile
$GISDBASE/$LOCATION_NAME/$MAPSET/*/$pattern

-----Import script-----------
#/bin/sh
#Import script for files created using the export
script
#unpacks the export file inside the user
gisdbase/location/mapset
#can be substitude by just tar -jcPvf export.file.name
#created by Daniel de Castro Victoria on 12/02/2003
#daniel_victoria@yahoo.com

echo Enter export file name:
read outfile

tar -jxPvf $outfile

--- Daniel Victoria <daniel_victoria@yahoo.com> wrote:

Hi all,

Thanks Glynn for the help.

But imagine this, you have 300 rasters and want to
erase half, but keep a backup. Wouldn't it be
easier/better to have a way to backup just those
rasters and not the entire dataset? Then, if later
on,
I want to restore just 10 of those 150 backup
rasters,
It would be very easy o do. Maybe some sort of
export
program designed to export from Grass to a
interchange
file and back to Grass, like the export program in
ARC...

Of course, since it's just a matter of getting all
the
files and directories with the same name as the
raster, a simple shell script will do the trick...
I'll try to work on that and if successful, post it
to
the list, but keep in mind that I'm a newbie at
programing... If anyone beats me to the task, feel
free to contribute :slight_smile:

Daniel

--- Glynn Clements <glynn.clements@virgin.net>
wrote:
>
> Daniel Victoria wrote:
>
> > I need to remove some grass rasters from my HD
> since
> > it's almost filled up, but I don't want to loose
> the
> > files. What would be the best way to do this? Is
> there
> > such a command like export, so I can do a safe
> backup
> > of the files? Should I use r.out.ascii,
r.out.bin?
> Or
> > just copy the entire directory?
>
> Backing-up an entire mapset is simple enough; just
> use tar/zip/etc on
> the mapset directory. Similarly for entire
> locations.
>
> Backing-up individual maps is a bit more involved;
> however, all files
> pertaining to a given map have the same name as
the
> map, except for
> those in the cell_misc directory, which reside in
a
> subdirectory with
> the same name as the map. In both cases, the
> file/directory in
> question will exist in a subdirectory of the
mapset
> directory. So you
> could use e.g.:
>
> cd <database>/<location>/<mapset>
> tar cf <mapname>.tar */<mapname>
>
> Using r.out.* will discard the category labels,
> colour table, history
> etc, so it isn't a particularly good mechanism for
> creating backups.
>
> --
> Glynn Clements <glynn.clements@virgin.net>
>

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/

Daniel Victoria wrote:

Just to finish the topic.

I made 2 shell scripts, one that will tar/bzip2 all
maps with a specific name to a tar.bz2 file and the
other that will unpack it. The unpacking is not
necessary since it can be done by simply using the
command
tar -jxPvf file_name
the P is to keep the original file path

Hope it can be usefull to anyone. Feel free to change
it as you see fit

tar -jcPvf $outfile
$GISDBASE/$LOCATION_NAME/$MAPSET/*/$pattern

Presumably this was meant to be a single line, but was wrapped by your
mail client?

A few points:

1. You can't rely upon $GISDBASE, $LOCATION_NAME or $MAPSET being set;
in 5.0.0 and later, these settings aren't stored in environment
variables. The script would need to do:

  eval `g.gisenv`

to set those variables.

2. One potential problem with using absolute pathnames is that you
might exceed the maximum length of a command line, particularly if
$GISDBASE is long and a map has a large number of components. If you
want complete pathnames in the tar file, a more reliable approach
would be:

  dir="$GISDBASE/$LOCATION_NAME/$MAPSET"
  cd "$dir"
  for file in */$pattern ; do
      echo "$dir/$file"
  done | tar cjPvfT "$outfile" -

3. Personally, I wouldn't use absolute paths, but would at least make
them relative to $GISDBASE, so that they can still be extracted if
$GISDBASE moves. E.g.

  root="$GISDBASE"
  dir="$LOCATION_NAME/$MAPSET"
  ( cd "$root/$dir"
    for file in */$pattern ; do
        echo "$dir/$file"
    done ) | tar cjPvCfT "$root" "$outfile" -

A similar argument could be made about using paths which are relative
to either the location or mapset directory. However, the arguments for
including either the location or location+mapset directories are
somewhat stronger than for the database directory (i.e. they form part
of the database' structure).

Having said all that, the ultimate solution would be to use the code
in src/general/manage (g.copy etc) to produce a utility which lists
all of the files which actually comprise a map (via etc/element_list).

That would eliminate false positives, i.e. files with the same name as
a map but which aren't actually part of that map. This is particularly
relevant if you have raster/vector/sites maps with the same name.

--
Glynn Clements <glynn.clements@virgin.net>

But imagine this, you have 300 rasters and want to
erase half, but keep a backup. Wouldn't it be
easier/better to have a way to backup just those
rasters and not the entire dataset? Then, if later on,
I want to restore just 10 of those 150 backup rasters,
It would be very easy o do.

You could create a new mapset, then use
g.copy rast="$oldmap"@oldlocation,"$oldmap"

[maybe feed with cropped output from g.mlist]

then just tar.gzip up the new mapset and the PERMANENT directory to save
the projection info (assuming it isn't full of maps).

This problem is cleared up for vectors in 5.7, hopefully for rasters
when they get their re-write one day.

good luck,
Hamish

Once again, thanks Glynn,

After reading the e-mail a couple of times I finaly
understood everything... Things are allways more
complicated then what they seam....

I'll see if later this week I'll make some changes on
the script. If not usable, it will at least be a cool
exercise

Thanks again for the eye opener

Daniel

--- Glynn Clements <glynn.clements@virgin.net> wrote:

Daniel Victoria wrote:

> Just to finish the topic.
>
> I made 2 shell scripts, one that will tar/bzip2
all
> maps with a specific name to a tar.bz2 file and
the
> other that will unpack it. The unpacking is not
> necessary since it can be done by simply using the
> command
> tar -jxPvf file_name
> the P is to keep the original file path
>
> Hope it can be usefull to anyone. Feel free to
change
> it as you see fit

> tar -jcPvf $outfile
> $GISDBASE/$LOCATION_NAME/$MAPSET/*/$pattern

Presumably this was meant to be a single line, but
was wrapped by your
mail client?

A few points:

1. You can't rely upon $GISDBASE, $LOCATION_NAME or
$MAPSET being set;
in 5.0.0 and later, these settings aren't stored in
environment
variables. The script would need to do:

  eval `g.gisenv`

to set those variables.

2. One potential problem with using absolute
pathnames is that you
might exceed the maximum length of a command line,
particularly if
$GISDBASE is long and a map has a large number of
components. If you
want complete pathnames in the tar file, a more
reliable approach
would be:

  dir="$GISDBASE/$LOCATION_NAME/$MAPSET"
  cd "$dir"
  for file in */$pattern ; do
      echo "$dir/$file"
  done | tar cjPvfT "$outfile" -

3. Personally, I wouldn't use absolute paths, but
would at least make
them relative to $GISDBASE, so that they can still
be extracted if
$GISDBASE moves. E.g.

  root="$GISDBASE"
  dir="$LOCATION_NAME/$MAPSET"
  ( cd "$root/$dir"
    for file in */$pattern ; do
        echo "$dir/$file"
    done ) | tar cjPvCfT "$root" "$outfile" -

A similar argument could be made about using paths
which are relative
to either the location or mapset directory. However,
the arguments for
including either the location or location+mapset
directories are
somewhat stronger than for the database directory
(i.e. they form part
of the database' structure).

Having said all that, the ultimate solution would be
to use the code
in src/general/manage (g.copy etc) to produce a
utility which lists
all of the files which actually comprise a map (via
etc/element_list).

That would eliminate false positives, i.e. files
with the same name as
a map but which aren't actually part of that map.
This is particularly
relevant if you have raster/vector/sites maps with
the same name.

--
Glynn Clements <glynn.clements@virgin.net>

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/