-1

I'd like to copy a dir and its contents in RAM, do my routines and periodically make some backups/sync on my original dir.

So if I have a dir mydir/ with 2 files:

$ ls mydir/
file1.tex  file2.tex

I can mount it with:

sudo mount -t tmpfs -o size=100m tmpfs ~/mydir

but the mounted one it's empty (as expected):

$ ls mydir/
$ 

1 - Is it possible to keep the original mydir's contents in my mounted mydir?

2 - Is it possible to sync (let's say, every 5 minutes) the mounted mydir with mydir on the hard drive? I red about the bind option but I'm not sure of how it works.

  • 1
    It shows as empty because you are mounting a temporary filesystem over your existing mydir directory. – Peschke Dec 3 '18 at 16:16
  • @Peschke Now that I understood. I wondered if is it possible to keep making operation on that dir (the HD one). – Gabriele Nicolardi Dec 3 '18 at 16:28
0


Yes, you can keep your current mydir contents. Explore mount --bind
Yes, it is possable to sync every 5 minutes with like rsync and the mount --bind commands.

I would however, make a separate directory to mount:
Say, mkdir /home/user/memdrive.

You should make a script:

#!/bin/bash
if mount | grep /home/user/memdrive > /dev/null; then
    cp /home/user/memdrive /mydir
    else
    mount -t tmpfs -o size=100M tmpfs /home/user/memdrive
    cp /mydir /home/user/memdrive
    umount /home/user/memdrive
fi

If the memdrive is not mounted it will mount it and copy the contense of /mydir to it.
If the memdrive is mounted it will cp /home/user/memdrive back to /mydir then unmount.

Modify to suit your needs.

You could also do all of these manually or do them in a different script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.