How to Store Data Permanently in /Tmp Directory in Linux

How to store data permanently under /tmp in linux?

By your df summary, /tmp is a tmpfs -- meaning it is not "real" storage -- its a RAM filesystem whose contents will be lost whenever the power goes off.

linux /tmp folder + how to know if files will deleted after reboot or after some time

This is specified in the File Hierarchy Standard and Linux Standard Base

/tmp/ is often tmpfs mounted, and on systems where it is not the case, the boot init scripts should (and usually do) clean it.

So files under /tmp/ do not survive a reboot. Put them elsewhere (perhaps /var/tmp/) if you want them to survive a reboot.


In the FHS §2.3:

The /tmp directory must be made available for programs that require temporary files.

Programs must not assume that any files or directories in /tmp are preserved between invocations of the program.

Tip Rationale

IEEE standard P1003.2 (POSIX, part 2) makes requirements that are similar to the above section.

Although data stored in /tmp may be deleted in a site-specific manner, it is recommended that files and directories located in /tmp be deleted whenever the system is booted.


So unless your systems are very badly misconfigured, you should presume that /tmp/ is cleaned at least at reboot time. BTW, some sysadmins are setting a crontab entry to clean old files (e.g. weekly clean older than 2 weeks file). See also tmpfiles.d(5), TMPDIR, mkstemp(3), crontab(5), POSIX tmpfile & tmpnam

Where to store application data (non-user specific) on Linux

It depends on what kind of data you're planning on storing. This answer is under the premise that you're storing and modifying data at run time.

Contrary to what others have suggested, I would recommend against using /usr/share for storage. From the Filesystem Hierarchy Standard:

The /usr/share hierarchy is for all
read-only architecture independent
data files.

As you're modifying data, this goes against the read-only nature of the /usr subsystem.

A seemingly better place to store your application state data would be /var, or more specifically, /var/lib. This also comes from the Hierarchy Standard. You could create a /var/lib/myapp, or if you're also using things like lock files or logs, you could leverage /var/lock or /var/log.

Have a deeper look at the standard as a whole (linked to above)—you might find a place that fits what you want to do even better.

Like Steve K, I would also recommend using the Preferences API for application preference data.

Where to store temporary data (embedded C)

I don't quite get why you say "using the heap is counter-intuitive" - Millions of embedded routers and switches use the heap for store-and-forward queues (I understand what you do is similar).

It very much depends on the data that you acquire. Anything that can be re-acquired in case of a power failure or other reset events of your device doesn't really need to go into permanent storage.

Data that is hard or impossible to re-acquire and this valuable (like sensor data , for example), you might possibly want to push into a safe place where it is protected from resets and power-down, however.

On the other hand, if your data is not segmented but rather stream-oriented, storing it to a file might be a lot easier - Also beware that out-of-memory conditions and heap memory leaks can be a real nuisance to debug in embedded systems.

How to create a temporary directory?

Use mktemp -d. It creates a temporary directory with a random name and makes sure that file doesn't already exist. You need to remember to delete the directory after using it though.

How to create permanent Symbolic link in /tmp folder to start postgres?

Add it to the startup script. You won't need sudo as all startup scripts are run as root. It should be located in /etc/init.d, so you can edit it with sudo vim /etc/init.d/postgres.

Temporary directory persist across program runs

http://pypi.python.org/pypi/appdirs is a Python module that offers a cross-platform user_cache_dir function.



Related Topics



Leave a reply



Submit