[SOLVED] What order should I restore timestamps including with debugfs?
UbuntuThis forum is for the discussion of Ubuntu Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I guess that recording may be good enough until I get a safe enough way to set created at times. I have never seen a changed at time setter. I think I actually saw another thing called debugfs without a ext4. I am not totally sure but at least it is for all ext2 to ext4. I know subsecond precision is included in like my recordings. Thanks. X E.
I think I meant like do not use this on your main hardware file system like for example /dev/sda1. Why I do not try it is it is supposedly dangerous for running systems. I would like a full backup before that and all USB sticks I currently have are toast, hold stuff I would rather not erase to use as ext4, or are that one USB that won't write as ext4. I would do it like myself if I had a backup. Since you ran it, can you run "set_inode_field -l" and post result? That would be in debugfs shell. To sum up what I found, there is a kernel option that must be enabled to have debugfs work. CONFIG_DEBUG_FS=y
That I do not know how to enable or check. I thought others were useful because they were how other people used debugfs successfully. If you do not have a good backup, get one before continuing this Petri Kaukasoina. Not much else in those links. Also, in debugfs "help" might be good. Knowing you, you probably have a good backup. Not sure why I am like alone on this save crtime and ctime thing. X E.
Thanks Petri Kaukasoina, it works for change time. Also, I do not have a root password and would recommend using sudo. Also, are you using a secondary partition? Nice if you are, I do not have that. Maybe I should use this on an ext4 USB if I ever get one to use. Maybe soon. Also, I thought debugfs was like no / start for relative to outside of debugfs pwd and inside debugfs /something... meant inside debugfs file system. I thought many said do not ever use this on a mounted file system. I guess if mounted as debugfs it is safe enough. Your tests are ground breaking. X E.
I think I meant like do not use this on your main hardware file system like for example /dev/sda1. Why I do not try it is it is supposedly dangerous for running systems.
Yes, I tested it on /dev/sdc1 which was not mounted while I ran the debugfs command. I only mounted it for running stat to see the results.
If you want to use it on your main OS, you can boot to a live linux (usb stick) and use debugfs there to edit your main file systems on disk.
You don't need to be root or need write access to any fs if you want to see what you asked:
Code:
$ debugfs
debugfs 1.47.0 (5-Feb-2023)
debugfs: sif -l
Inode fields supported by the set_inode command:
mode unsigned integer
uid[_hi|_lo] unsigned integer
size[_hi|_lo] unsigned integer
atime[_hi|_lo] date/time
ctime[_hi|_lo] date/time
mtime[_hi|_lo] date/time
dtime date/time
gid[_hi|_lo] unsigned integer
links_count unsigned integer
blocks[_hi|_lo] unsigned integer
flags unsigned integer
version[_hi|_lo] unsigned integer
translator unsigned integer
block[12] unsigned integer
block[IND] unsigned integer
block[DIND] unsigned integer
block[TIND] unsigned integer
generation unsigned integer
file_acl[_hi|_lo] unsigned integer
faddr unsigned integer
frag unsigned integer
fsize unsigned integer
checksum[_hi|_lo] unknown
author unsigned integer
extra_isize unsigned integer
ctime_extra unsigned integer
mtime_extra unsigned integer
atime_extra unsigned integer
crtime[_hi|_lo] date/time
crtime_extra unsigned integer
projid unsigned integer
bmap[] set physical->logical block map
debugfs: help
Available debugfs requests:
show_debugfs_params, params
Show debugfs parameters
open_filesys, open Open a filesystem
close_filesys, close Close the filesystem
freefrag, e2freefrag Report free space fragmentation
feature, features Set/print superblock features
dirty_filesys, dirty Mark the filesystem as dirty
init_filesys Initialize a filesystem (DESTROYS DATA)
show_super_stats, stats Show superblock statistics
ncheck Do inode->name translation
icheck Do block->inode translation
change_root_directory, chroot
Change root directory
change_working_directory, cd
Change working directory
list_directory, ls List directory
show_inode_info, stat Show inode information
dump_extents, extents, ex
Dump extents information
blocks Dump blocks used by an inode
filefrag Report fragmentation information for an inode
link, ln Create directory link
unlink Delete a directory link
mkdir Create a directory
rmdir Remove a directory
rm Remove a file (unlink and kill_file, if appropriate)
kill_file Deallocate an inode and its blocks
copy_inode Copy the inode structure
clri Clear an inode's contents
freei Clear an inode's in-use flag
seti Set an inode's in-use flag
testi Test an inode's in-use flag
freeb Clear a block's in-use flag
setb Set a block's in-use flag
testb Test a block's in-use flag
modify_inode, mi Modify an inode by structure
find_free_block, ffb Find free block(s)
find_free_inode, ffi Find free inode(s)
print_working_directory, pwd
Print current working directory
expand_dir, expand Expand directory
mknod Create a special file
list_deleted_inodes, lsdel
List deleted inodes
undelete, undel Undelete file
write Copy a file from your native filesystem
dump_inode, dump Dump an inode out to a file
cat Dump an inode out to stdout
lcd Change the current directory on your native filesystem
rdump Recursively dump a directory to the native filesystem
set_super_value, ssv Set superblock value
set_inode_field, sif Set inode field
set_block_group, set_bg Set block group descriptor field
logdump Dump the contents of the journal
htree_dump, htree Dump a hash-indexed directory
dx_hash, hash Calculate the directory hash of a filename
dirsearch Search a directory for a particular filename
bmap Calculate the logical->physical block mapping for an inode
fallocate Allocate uninitialized blocks to an inode
punch, truncate Punch (or truncate) blocks from an inode by deallocating them
symlink Create a symbolic link
imap Calculate the location of an inode
dump_unused Dump unused blocks
set_current_time Set current time to use when setting filesystem fields
supported_features Print features supported by this version of e2fsprogs
dump_mmp Dump MMP information
set_mmp_value, smmp Set MMP value
extent_open, eo Open inode for extent manipulation
zap_block, zap Zap block: fill with 0, pattern, flip bits etc.
block_dump, bdump, bd Dump contents of a block
ea_list List extended attributes of an inode
ea_get Get an extended attribute of an inode
ea_set Set an extended attribute of an inode
ea_rm Remove an extended attribute of an inode
list_quota, lq List quota
get_quota, gq Get quota
inode_dump, idump, id Dump the inode structure in hex
journal_open, jo Open the journal
journal_close, jc Close the journal
journal_write, jw Write a transaction to the journal
journal_run, jr Recover the journal
help Display info on command or topic.
list_requests, lr, ? List available commands.
quit, q Leave the subsystem.
Quote:
To sum up what I found, there is a kernel option that must be enabled to have debugfs work. CONFIG_DEBUG_FS=y
No. It is a totally different thing. It is a virtual file system used by kernel developers to debug the kernel.
Last edited by Petri Kaukasoina; 01-13-2024 at 11:24 AM.
All needed is that format. In set_inode_field (sif) I saw it could be date/time. Anyway, now just how to set based on these. Also, I think I really should thank you somehow if I can more than just saying it, so how about you get to use like my timestamp recorder and restorer if it ever gets done? I will do like my own research on how to convert too. X E.
I realize now that I will need to have setting be all debugfs usage and I am unsure how if there is a way to get if a file or folder exists in debugfs because I do not want to screw with non-existent things. I have code that should set it all but can't check existence and may need that. If I use this for full backup, would nothing change if I use a bootable USB, record all timestamps on computer main to a file, then rsync whole main to a USB not using main except as to get from? I realize now there IS ls so I may use that. X E.
Last edited by maybeJosiah; 01-13-2024 at 12:29 PM.
Reason: more info maybe
# File to check for existence
result="/path/to/file"
# Run the debugfs command to check if the file exists
output=$(debugfs -R "stat "$result"" "$device" 2>/dev/null)
# Check the output for the existence of the file
if [[ $output =~ "File not found" ]]; then
exists=false
else
exists=true
fi
# Print the result
echo "File exists: $exists"
#X E.
For maybe getting if file exists. I got that from zzzcode.ai so unsure. Looks like created, accessed, modified, changed times. Thank you. I think that because crtime should be like constant. Just to be sure though, can you run it with different times for mtime and ctime? Note: never /dev/sda1. X E.
Last edited by maybeJosiah; 01-13-2024 at 12:45 PM.
Reason: X E.
I realize now that I will need to have setting be all debugfs usage and I am unsure how if there is a way to get if a file or folder exists in debugfs because I do not want to screw with non-existent things. I have code that should set it all but can't check existence and may need that.
No problem, you get a message:
Code:
root@linux:~ # debugfs -w /dev/sdc1
debugfs 1.43.1 (08-Jun-2016)
debugfs: sif /home/kaukasoi/non_existant_file atime 20231220010904
/home/kaukasoi/non_existant_file: File not found by ext2_lookup
debugfs: sif /home/kaukasoi/.bash_history atime 20231220010904
debugfs: q
root@linux:~ #
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.