DEV Community

Cover image for 6.Linux User Data Transfer
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

6.Linux User Data Transfer

Lab Information

Due to an accidental data mix-up, user data was unintentionally mingled on Nautilus App Server 3 at the /home/usersdata location by the Nautilus production support team in Stratos DC. To rectify this, specific user data needs to be filtered and relocated. Here are the details:

Locate all files (excluding directories) owned by user mark within the /home/usersdata directory on App Server 3. Copy these files while preserving the directory structure to the /blog directory.

Lab Solutions

🧭 Part 1: Lab Step-by-Step Guidelines (Technical Execution)

πŸ”Ή Step 1: Log in to Jump Host
ssh thor@jump_host.stratos.xfusioncorp.com

Password:

mjolnir123

πŸ”Ή Step 2: SSH into App Server 3
ssh banner@stapp03.stratos.xfusioncorp.com

Password:

BigGr33n

πŸ”Ή Step 3: Switch to Root

sudo -i
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 4: Move into source directory

⚠️ This step is critical for correct directory structure preservation.

cd /home/usersdata
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 5: Copy files owned by mark (files only)

find . -type f -user mark -exec cp --parents {} /blog \;
Enter fullscreen mode Exit fullscreen mode

βœ” . ensures relative path
βœ” -type f excludes directories
βœ” --parents preserves directory structure
βœ” Files copied under /blog correctly

πŸ”Ή Step 6: Verify copied files

find /blog -type f
Enter fullscreen mode Exit fullscreen mode

βœ… Final Checklist

βœ” Executed on App Server 3 only
βœ” Source: /home/usersdata
βœ” Only files selected (-type f)
βœ” Ownership filter: mark
βœ” Directory structure preserved
βœ” Files copied into /blog
βœ” Verified successfully

🧠 Part 2: Simple Step-by-Step Explanation (Beginner Friendly)

πŸ”Ή What is the task really asking?

Inside this directory:

/home/usersdata

There are files belonging to multiple users.

Your job is to:

Find only the files owned by user mark

Ignore directories

Copy those files

Keep their folder structure

Place them inside /blog

We are not moving, only copying.

πŸ”Ή Why do we use find?

Because we need to filter files based on:

Ownership (mark)

File type (files only, not folders)

Location (/home/usersdata)

The find command allows very precise filtering.

πŸ”Ή Why -type f?

-type f means:

Select files only.

If we don’t use this, directories might also be selected β€” which the lab does NOT want.

πŸ”Ή Why -user mark?

This ensures we only touch files owned by:

mark

Files owned by root, steve, or anyone else are ignored.

πŸ”Ή Why do we cd /home/usersdata first?

This is extremely important.

If we run:

find /home/usersdata ...

Then --parents will recreate the full path:

/blog/home/usersdata/...

That is usually NOT what the lab checker expects.

But if we do:

cd /home/usersdata
find .

Then the structure copied will look like:

/blog/

That is correct.

πŸ”Ή What does cp --parents do?

Normally, copying a file like:

project1/app/file.txt

Would place it directly into /blog like:

/blog/file.txt

But --parents preserves the full directory path, so it becomes:

/blog/project1/app/file.txt

This keeps the original structure intact.

πŸ”Ή Why must we run as root?

Because:

Some files may not be readable by normal users

Permission restrictions may block copying

Root avoids permission-related silent failures

πŸ”Ή Important Clarification About Ownership

When root copies files:

The copied files usually become owned by root

This is normal

The lab usually checks file presence and structure, not ownership

So don’t panic if:

find /blog -type f -user mark

returns nothing.

Instead check:

find /blog -type f

πŸ”Ή What Should Exist After Success?

If original file was:

/home/usersdata/site/config/settings.php

Then after copy, you should see:

/blog/site/config/settings.php

Same structure β€” different root directory.

πŸ” Why This Task Matters (Real-World Context)

This simulates:

Data recovery after accidental mixing

Filtering files by ownership

Migrating specific user data

Maintaining application directory integrity

These are common DevOps and production support tasks.


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)